如何使用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)
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)
| 归档时间: |
|
| 查看次数: |
7538 次 |
| 最近记录: |