Apache commons csv跳过行

g63*_*647 7 java csv

如何使用apache commons csv跳过输入文件中的行.在我的文件中,前几行是垃圾有用的元信息,如日期等.找不到任何选项.

private void parse() throws Exception {
    Iterable<CSVRecord> records = CSVFormat.EXCEL
            .withQuote('"').withDelimiter(';').parse(new FileReader("example.csv"));
    for (CSVRecord csvRecord : records) {
        //do something            
    }
}
Run Code Online (Sandbox Code Playgroud)

Ber*_*hot 5

FileReader.readLine()在启动之前使用for-loop

你的例子:

private void parse() throws Exception {
  FileReader reader = new FileReader("example.csv");
  reader.readLine(); // Read the first/current line.

  Iterable <CSVRecord> records = CSVFormat.EXCEL.withQuote('"').withDelimiter(';').parse(reader);
  for (CSVRecord csvRecord: records) {
    // do something
  }
}
Run Code Online (Sandbox Code Playgroud)