當前位置: 首頁>>代碼示例>>Java>>正文


Java CSVReader.readAll方法代碼示例

本文整理匯總了Java中au.com.bytecode.opencsv.CSVReader.readAll方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVReader.readAll方法的具體用法?Java CSVReader.readAll怎麽用?Java CSVReader.readAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在au.com.bytecode.opencsv.CSVReader的用法示例。


在下文中一共展示了CSVReader.readAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testWrite

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Test
public void testWrite() throws IOException { 
  String[] row1 = new String[] { "oneone", "onetwo", "onethree" };
  String[] row2 = new String[] { "twoone", "twotwo", "twothree" };

  StringWriter sWriter = new StringWriter();
  CSVWriter writer = new CSVWriter(sWriter, ',', '\'');

  writer.writeNext(row1);
  writer.writeNext(row2);

  String written = sWriter.toString();

  CSVReader reader = new CSVReader(new StringReader(written), ',', '\'');
  List<String[]> rows = reader.readAll();
  assertTrue(Arrays.equals(rows.get(0), row1));
  assertTrue(Arrays.equals(rows.get(1), row2));
}
 
開發者ID:casific,項目名稱:murmur,代碼行數:19,代碼來源:OpenCSVTest.java

示例2: addPartialTimesFromFile

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public void addPartialTimesFromFile(Path inputFilePath, FileSystem fileSystem) throws IOException {
    // Creates the reader.
    FSDataInputStream fileInputStream = fileSystem.open(inputFilePath);
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
    CSVReader fileReader = new CSVReader(bufferedReader);

    // Iterates among the lines.
    List<String[]> lines = fileReader.readAll();
    for (String[] line : lines) {
        // Reads data.
        int islandNumber = Integer.parseInt(line[ISLAND_NUMBER_PARTIAL_TIMES_HEADER_INDEX]);
        long generationsBlockNumber = Long.parseLong(line[GENERATIONS_BLOCK_NUMBER_PARTIAL_TIMES_HEADER_INDEX]);
        PhaseType phaseType = PhaseType.valueOf(line[PHASE_TYPE_PARTIAL_TIMES_HEADER_INDEX]);
        PartialTimeKey.Type partialTimeType = PartialTimeKey.Type.valueOf(line[TYPE_PARTIAL_TIMES_HEADER_INDEX]);
        long time = Long.parseLong(line[TIME_PARTIAL_TIMES_HEADER_INDEX]);

        // Adds the time.
        this.addPartialTime(islandNumber, generationsBlockNumber, phaseType, partialTimeType, time);
    }
}
 
開發者ID:pasqualesalza,項目名稱:elephant56,代碼行數:21,代碼來源:MapReduceTimeReporter.java

示例3: main

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
	
	CSVReader reader = new CSVReader(new FileReader(ADDRESS_FILE));
	String [] nextLine;
	while ((nextLine = reader.readNext()) != null) {
		System.out.println("Name: [" + nextLine[0] + "]\nAddress: [" + nextLine[1] + "]\nEmail: [" + nextLine[2] + "]");
	}
	
	// Try writing it back out as CSV to the console
	CSVReader reader2 = new CSVReader(new FileReader(ADDRESS_FILE));
	List allElements = reader2.readAll();
	StringWriter sw = new StringWriter();
	CSVWriter writer = new CSVWriter(sw);
	writer.writeAll(allElements);
	
	System.out.println("\n\nGenerated CSV File:\n\n");
	System.out.println(sw.toString());
	
	
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:21,代碼來源:AddressExample.java

示例4: extractRandomConfigs

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static void extractRandomConfigs(String inputFile, String outputFile, int nConfigs, int nIterations) throws IOException{
	CSVReader lines = new CSVReader(new FileReader(inputFile), ',');
	List<String[]> content = lines.readAll();
	
	for (int i=0; i<nIterations;i++){
		System.out.println(content.isEmpty());
		// Shuffle list
		Collections.shuffle(content);
		int randomNum = ThreadLocalRandom.current().nextInt(1, content.size() - nConfigs);
		// Write lines
		CSVWriter writer = new CSVWriter(new FileWriter(outputFile+(i+1)+".csv", true),';');
		for(int j=randomNum;j<=randomNum+nConfigs-1;j++){
			writer.writeNext(content.get(j));
		}
		writer.close();
	}
	
	lines.close();
}
 
開發者ID:axel-halin,項目名稱:Thesis-JHipster,代碼行數:20,代碼來源:CSVUtils.java

示例5: fromStream

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * Generate ReportData from an input stream (normally an HTTP steam of report in CSV format),
 * which will be closed after reading.
 * @param stream the input stream (in CSV format)
 * @param clientCustomerId the client customer ID of this report
 * @return the generated ReportData
 */
public ReportData fromStream(InputStream stream, Long clientCustomerId) throws IOException {
  CSVReader csvReader = new CSVReader(new InputStreamReader(stream, Charset.defaultCharset()));
  String[] headerArray = csvReader.readNext();
  List<String[]> rowsArray = csvReader.readAll();
  csvReader.close();

  int rowsCount = rowsArray.size();
  List<List<String>> rows = new ArrayList<List<String>>(rowsCount);
  for (int i = 0; i < rowsCount; ++i) {
    // need to create a new ArrayList object which is extendible.
    List<String> row = new ArrayList<String>(Arrays.asList(rowsArray.get(i)));
    rows.add(row);
  }

  int columns = headerArray.length;
  List<String> columnNames = new ArrayList<String>(columns);
  for (int i = 0; i < columns; i++) {
    String fieldName = fieldsMapping.get(headerArray[i]);
    Preconditions.checkNotNull(fieldName, "Unknown field name: %s.", fieldName);
    columnNames.add(fieldName);
  }

  return new ReportData(clientCustomerId, reportType, columnNames, rows);
}
 
開發者ID:googleads,項目名稱:adwords-alerting,代碼行數:32,代碼來源:ReportDataLoader.java

示例6: readInternal

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Override
protected QuoteWrapper readInternal(Class<? extends QuoteWrapper> clazz, HttpInputMessage httpInputMessage) throws IOException, HttpMessageNotReadableException {
    CSVReader reader = new CSVReader(new InputStreamReader(httpInputMessage.getBody()));
    List<String[]> rows = reader.readAll();
    QuoteWrapper quoteWrapper = new QuoteWrapper();
    for (String[] row : rows) {
    	quoteWrapper.add(new YahooQuote(row[0], 
    								row[1], 
    								parseDouble(row[2]), 
    								parseDouble(row[3]), 
    								parseDouble(row[4]), 
    								parseDouble(row[5]), 
    								parsePercent(row[6]), 
    								parseDouble(row[7]), 
    								parseDouble(row[8]), 
    								parseDouble(row[9]), 
    								parseDouble(row[10]), 
    								parseInt(row[11]), 
    								row[12], 
    								row[13]));
    }

    return quoteWrapper;
}
 
開發者ID:alex-bretet,項目名稱:cloudstreetmarket.com,代碼行數:25,代碼來源:YahooQuoteMessageConverter.java

示例7: readInternal

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Override
protected QuoteWrapper readInternal(Class<? extends QuoteWrapper> clazz, HttpInputMessage httpInputMessage) throws IOException, HttpMessageNotReadableException {
    CSVReader reader = new CSVReader(new InputStreamReader(httpInputMessage.getBody()));
    List<String[]> rows = reader.readAll();
    QuoteWrapper quoteWrapper = new QuoteWrapper();
    for (String[] row : rows) {

    	quoteWrapper.add(new YahooQuote(row[0], 
    								row[1], 
    								parseDouble(row[2]), 
    								parseDouble(row[3]), 
    								parseDouble(row[4]), 
    								parseDouble(row[5]), 
    								parsePercent(row[6]), 
    								parseDouble(row[7]), 
    								parseDouble(row[8]), 
    								parseDouble(row[9]), 
    								parseDouble(row[10]), 
    								parseInt(row[11]), 
    								row[12], 
    								row[13]));
    }

    return quoteWrapper;
}
 
開發者ID:alex-bretet,項目名稱:cloudstreetmarket.com,代碼行數:26,代碼來源:YahooHistoMessageConverter.java

示例8: readCSV

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * CSVファイルを読み込む
 * @param filepath ファイルパス
 * @return Stringのリスト
 */
public static List<String[]> readCSV(String filepath) {
    File csvfile = new File(filepath);
    if (csvfile.exists()){
        try {
            // 文字コード判別
            String encode = "UTF8";
            if (!Utils.checkUTF8(csvfile)) {
                encode = "ms932";
            }
            // CSV読み込み
            InputStream stream = new FileInputStream(csvfile);
            InputStreamReader reader = new InputStreamReader(stream, encode);
            BufferedReader buffer = new BufferedReader(reader);
            CSVReader csvReader = new CSVReader(buffer, ',', '"', 0);
            // 各行読み込み
            return csvReader.readAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
開發者ID:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:28,代碼來源:Utils.java

示例9: getPersistedObjects

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public List<PersistedObject> getPersistedObjects()
{
    List<PersistedObject> persistedObjects = new ArrayList<>();
    try
    {
        CSVReader reader = new CSVReader(new FileReader(NameFactory.PERSISTENCE_CSV));
        List<String[]> allEntries = reader.readAll();
        reader.close();
        for (String[] entry : allEntries)
        {
            persistedObjects.add(new PersistedObject(entry[1], entry[0]));
        }
    }
    catch (Exception e)
    {
        App.kill(e);
    }

    return persistedObjects;
}
 
開發者ID:philipperemy,項目名稱:Leboncoin,代碼行數:21,代碼來源:Persistence.java

示例10: persist

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
private synchronized boolean persist(String id, String hash, boolean append) throws IOException
{
    // Append
    CSVReader reader = new CSVReader(new FileReader(NameFactory.PERSISTENCE_CSV));
    List<String[]> allEntries = reader.readAll();
    for (String[] entry : allEntries)
    {
        if (entry[0].equals(hash))
        {
            reader.close();
            return false;
        }
    }
    reader.close();

    CSVWriter writer = new CSVWriter(new FileWriter(NameFactory.PERSISTENCE_CSV, append));
    String[] entries = new String[2];
    entries[0] = hash;
    entries[1] = id;
    writer.writeNext(entries);
    writer.close();
    return true;
}
 
開發者ID:philipperemy,項目名稱:Leboncoin,代碼行數:24,代碼來源:Persistence.java

示例11: read

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
private void read() throws IOException
{
    if (firstRead)
    {
        CSVReader reader = new CSVReader(new FileReader(NameFactory.CONF_PATH_FILE));
        List<String[]> items = reader.readAll();
        confItems = new ArrayList<>();
        for (String[] item : items)
        {
            ConfItem confItem = createConfItem(item);
            Logger.traceINFO(confItem.toString());
            confItems.add(confItem);
        }

        reader.close();
        firstRead = false;
    }
}
 
開發者ID:philipperemy,項目名稱:Leboncoin,代碼行數:19,代碼來源:ConfReader.java

示例12: importCsv

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static SortedMap<Number, Number> importCsv(String filePath) {
	try {
		reader = new CSVReader(new FileReader(filePath));
		List<String[]> entries = reader.readAll();
		SortedMap<Number, Number> data = new TreeMap<>();

		for (String[] line : entries) {
			if (line.length == 2) {
				Number x = NumberFormat.getNumberInstance(LOCALE).parse(line[0]);
				Number y = NumberFormat.getNumberInstance(LOCALE).parse(line[1]);
				data.put(x, y);
			}
		}

		reader.close();
		return data;
	} catch (IOException | ParseException e) {
		System.err.println(e.getMessage());
	}
	return Collections.emptySortedMap();
}
 
開發者ID:tesis-dynaware,項目名稱:fancy-chart,代碼行數:22,代碼來源:CsvDao.java

示例13: loadAffinities

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public void loadAffinities( String fn ) throws IOException
{
	logger.info(" loading affinities from " + fn);
	
	 CSVReader csvReader = new CSVReader(new FileReader(fn),',');
	 List<String[]> rows = csvReader.readAll();
	 
	 if( edgelAffinities == null ){
		 edgelAffinities = new HashMap<EdgelPair, Double>();
	 }
	 
	 for ( String[] row : rows ){
		 int k = 0;
		 
		 Edgel e = new Edgel(
				 new double[]{	Double.parseDouble(row[k++]),
						 		Double.parseDouble(row[k++]),
						 		Double.parseDouble(row[k++])},
				new double[]{	Double.parseDouble(row[k++]),
					 			Double.parseDouble(row[k++]),
					 			Double.parseDouble(row[k++])},
				Double.parseDouble(row[k++])
			);
	 }
	 
}
 
開發者ID:bogovicj,項目名稱:hhmi-exp,代碼行數:27,代碼來源:EdgelMatching.java

示例14: getResults

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * Returns the Fusion Tables CSV response as a {@code QueryResults} object.
 *
 * @return an object containing a list of column names and a list of row values from the
 *         Fusion Tables response
 */
private QueryResults getResults(GDataRequest request)
    throws IOException {
  InputStreamReader inputStreamReader = new InputStreamReader(request.getResponseStream());
  BufferedReader bufferedStreamReader = new BufferedReader(inputStreamReader);
  CSVReader reader = new CSVReader(bufferedStreamReader);
  // The first line is the column names, and the remaining lines are the rows.
  List<String[]> csvLines = reader.readAll();
  List<String> columns = Arrays.asList(csvLines.get(0));
  List<String[]> rows = csvLines.subList(1, csvLines.size());
  QueryResults results = new QueryResults(columns, rows);
  return results;
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:19,代碼來源:ClientStatsFusionLoader.java

示例15: testRead

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Test
public void testRead() throws IOException {
  String csv = "one,two,three\none,five,six\none,2.0,'124124.1241241.12,12412,1,4'";
  InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(csv.getBytes("UTF-8")));
  CSVReader reader = new CSVReader(isr, ',', '\'');
  List<String[]> rows = reader.readAll();
  for (String[] row : rows) {
    assertEquals("one", row[0]);
    assertEquals(3, row.length);
  }

}
 
開發者ID:casific,項目名稱:murmur,代碼行數:13,代碼來源:OpenCSVTest.java


注:本文中的au.com.bytecode.opencsv.CSVReader.readAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。