au.com.bytecode.opencsv.CSVReader类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中au.com.bytecode.opencsv.CSVReader类的一些代码示例,展示了CSVReader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CSVReader类的具体详情如下:
包路径:au.com.bytecode.opencsv.CSVReader
类名称:CSVReader

CSVReader介绍

[英]A very simple CSV reader released under a commercial-friendly license.
[中]一个非常简单的CSV阅读器,根据商业友好许可证发布。

代码示例

代码示例来源:origin: stackoverflow.com

CSVReader reader=new CSVReader(
  new InputStreamReader(new FileInputStream("d:\\a.csv"), "UTF-8"), 
  ',', '\'', 1);
String[] line;
while ((line = reader.readNext()) != null) {
  StringBuilder stb = new StringBuilder(400);
  for (int i = 0; i < line.length; i++) {
     stb.append(line[i]);
     stb.append(";");
  }
  System.out.println(stb);
}

代码示例来源:origin: stackoverflow.com

FileInputStream fis = new FileInputStream("awesomefile.csv"); 
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
CSVReader reader = new CSVReader(isr);

for (String[] row; (row = reader.readNext()) != null;) {
  System.out.println(Arrays.toString(row));
}

reader.close();
isr.close();
fis.close();

代码示例来源:origin: databricks/learning-spark

public Iterable<String[]> call(Tuple2<String, String> file) throws Exception {
  CSVReader reader = new CSVReader(new StringReader(file._2()));
  return reader.readAll();
 }
}

代码示例来源:origin: databricks/learning-spark

public Tuple2<Integer, String[]> call(String line) throws Exception {
  CSVReader reader = new CSVReader(new StringReader(line));
  String[] elements = reader.readNext();
  Integer key = Integer.parseInt(elements[0]);
  return new Tuple2(key, elements);
 }
}

代码示例来源:origin: stackoverflow.com

try (InputStream stream = new FileInputStream(filepath)) {
  CSVReader reader = new CSVReader(new InputStreamReader(stream, "UTF-8"));
  ...
}

代码示例来源:origin: stackoverflow.com

String next[] = {};
   List<String[]> list = new ArrayList<String[]>();
   try {
     CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open("test.csv")));
     while(true) {
       next = reader.readNext();
       if(next != null) {
         list.add(next);
       } else {
         break;
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }

代码示例来源:origin: stackoverflow.com

try {
  CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(new File("/path/to/your/file.csv"))));
  Map<String, String> result = new HashMap<String, String>();
  for(String[] row : reader.readAll()) {
    result.put(row[0], row[1]);
  }
} catch (FileNotFoundException e1) {
  e1.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

FileInputStream fis = new FileInputStream(file);
     CSVReader reader = new CSVReader(new BufferedReader( new InputStreamReader(fis, "UTF-8" )));
     ArrayList<String> row = new ArrayList<String>();
     ArrayList<Entry> entries = new ArrayList<Entry>();
     // a line = ID, Name, Price, Description
     while (!reader.isEOF()) {
       reader.readFields(row);
       if( row.size() >= 4)
         entries.add(new Entry(row.get(0), row.get(1), row.get(2), row.get(3)));
     }
     System.out.println("Size : "+entries);

代码示例来源:origin: stackoverflow.com

CsvToBean<Person> csvToBean = new CsvToBean<Person>();

Map<String, String> columnMapping = new HashMap<String, String>();
columnMapping.put("Id", "id");
columnMapping.put("Fname", "fname");
columnMapping.put("Lname", "lname");

HeaderColumnNameTranslateMappingStrategy<Person> strategy = new HeaderColumnNameTranslateMappingStrategy<Person>();
strategy.setType(Person.class);
strategy.setColumnMapping(columnMapping);

List<Person> list = null;
CSVReader reader = new CSVReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.csv")));
list = csvToBean.parse(strategy, reader);

代码示例来源:origin: org.molgenis/molgenis-one-click-importer

@Override
public List<String[]> buildLinesFromFile(File file) throws IOException {
 CSVReader reader =
   createCsvReader(file.getName(), removeByteOrderMark(new FileInputStream(file)));
 List<String[]> content = reader.readAll();
 validateCsvFile(content, file.getName());
 return content;
}

代码示例来源:origin: stackoverflow.com

public class ExampleCSVWrite {
  public static void main (String[] args) throws IOException {
   CSVReader reader = new CSVReader(new  FileReader("/Users/aaronarpi/Documents/UA.csv"));
   List<String[]> myEntries = reader.readAll();
   reader.close();
  }
}

代码示例来源:origin: stackoverflow.com

CSVReader reader1 = new CSVReader(new FileReader(mydata_csv.getpath()));
List<String[]> myDatas = reader1.readAll();
String[] lineI = myDatas.get(i);
for (String[] line : myDatas) {
  for (String value : line) {
    //do stuff with value
  }
}

代码示例来源:origin: forcedotcom/phoenix

@Test
public void testCSVUpsertWithAllColumn() throws Exception {
  // Create table
  String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);";
  PhoenixConnection conn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class);
  PhoenixRuntime.executeStatements(conn, new StringReader(statements), null);
  
  // Upsert CSV file
  CSVLoader csvUtil = new CSVLoader(conn, STOCK_TABLE, Arrays.asList("FOO","BAR"), false);
  CSVReader reader = new CSVReader(new StringReader(STOCK_CSV_VALUES));
  try {
    csvUtil.upsert(reader);
    fail();
  } catch (SQLException e) {
    assertTrue(e.getMessage(), e.getMessage().contains("ERROR 504 (42703): Undefined column. columnName=STOCK_SYMBOL.[FOO, BAR]"));
  }
  conn.close();
}

代码示例来源:origin: stackoverflow.com

String[] values = {"one", "two,three", "four , five"};
 CSVWriter writer = new CSVWriter(new FileWriter("yourfile.csv"));
 writer.writeNext(values);
 writer.close();

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] entries;
// reading just the first line
if ((entries = reader.readNext()) != null) {
  System.out.println(entries[0] + ", " + entries[1] + ", " + entries[2]);
}
reader.close();

代码示例来源:origin: jzy3d/jzy3d-api

/**********************************************/
protected static int readNLines(String filename) throws IOException {
  CSVReader reader = new CSVReader(new FileReader(filename));
  int n = 0;
  while (reader.readNext() != null)
    n++;
  reader.close();
  return n;
}

代码示例来源:origin: stackoverflow.com

public class ParseCSV {
 public static void main(String[] args) {
  try {
   //csv file containing data
   String strFile = "C:\\Users\\rsaluja\\CMS_Evaluation\\Drupal_12_08_27.csv";
   CSVReader reader = new CSVReader(new FileReader(strFile));
   String [] nextLine;
   int lineNumber = 0;
   while ((nextLine = reader.readNext()) != null) {
    lineNumber++;
    System.out.println("Line # " + lineNumber);

    // nextLine[] is an array of values from the line
    System.out.println(nextLine[4] + "etc...");
   }
  }
 }
}

代码示例来源:origin: stackoverflow.com

CSVReader reader = new CSVReader(new FileReader(file), ',', '\'', 1);

代码示例来源:origin: stackoverflow.com

char tokenSeparator = ',';
char quoteChar = '"';
String inputData[] = {"a","b","c"};

StringWriter stringWriter = new StringWriter();
CSVWriter csvWriter = new CSVWriter(stringWriter, tokenSeparator, quoteChar);
csvWriter.writeNext(inputData);
csvWriter.close();

StringReader stringReader = new StringReader(stringWriter.toString());
CSVReader csvReader = new CSVReader(stringReader, tokenSeparator, quoteChar);
String outputData[] = csvReader.readNext();

代码示例来源:origin: stackoverflow.com

CSVReader reader = new CSVReader(new FileReader("test test.txt"), ',');
   List<String []> myEntries = reader.readAll();
   reader.close ();
   CSVWriter writer = new CSVWriter(new FileWriter("test test.txt"), ',');
   //Iterate through my array
   for (String [] line : myEntries)
   {
     ArrayList<String> newLine = new ArrayList <String>();
     for (String word : line) {
     {
       String newVal = word.replace(strSerial, strLocation);
       newLine.add (newVal);
     }
     writer.writeNext(newLine.toArray(new String[newLine.size()]));
   }

代码示例来源:origin: pl.edu.icm.synat/synat-sdk-sample-services

private static void doWithCrossref(CrossrefService service, String inputFile, String outputFile) throws Exception {
  CSVReader reader = new CSVReader(new FileReader(inputFile));
  CSVWriter writer = new CSVWriter(new FileWriter(outputFile));
  
  try {
    List<String[]> allLines = reader.readAll();
    int counter = 0;
    for (String[] strings : allLines) {
      counter++;
      if (counter % 50 == 0) {
        System.out.println(counter + " of "+allLines.size());
        writer.flush();
      }
      String doi = strings[0];
      String[] line = findByCrossRef(service, doi);
      writer.writeNext(line);
    }
  }finally {
    IOUtils.closeQuietly(reader);
    IOUtils.closeQuietly(writer);
  }
}

相关文章