适用于 Java 的良好且有效的 CSV/TSV 阅读器
2022-09-03 13:04:44
我正在尝试读取大文件和(制表符分隔的)文件,其中包含大约行或更多。现在我试图用opencsv
阅读一个包含行,但它给我一个.它适用于带有行的较小文件。所以我想知道是否有任何其他支持读取巨大和文件。你有什么想法吗?CSV
TSV
1000000
TSV
~2500000
java.lang.NullPointerException
TSV
~250000
Libraries
CSV
TSV
每个对我的代码感兴趣的人(我缩短了它,所以显然是无效的):Try-Catch
InputStreamReader in = null;
CSVReader reader = null;
try {
in = this.replaceBackSlashes();
reader = new CSVReader(in, this.seperator, '\"', this.offset);
ret = reader.readAll();
} finally {
try {
reader.close();
}
}
编辑:这是我构造:InputStreamReader
private InputStreamReader replaceBackSlashes() throws Exception {
FileInputStream fis = null;
Scanner in = null;
try {
fis = new FileInputStream(this.csvFile);
in = new Scanner(fis, this.encoding);
ByteArrayOutputStream out = new ByteArrayOutputStream();
while (in.hasNext()) {
String nextLine = in.nextLine().replace("\\", "/");
// nextLine = nextLine.replaceAll(" ", "");
nextLine = nextLine.replaceAll("'", "");
out.write(nextLine.getBytes());
out.write("\n".getBytes());
}
return new InputStreamReader(new ByteArrayInputStream(out.toByteArray()));
} catch (Exception e) {
in.close();
fis.close();
this.logger.error("Problem at replaceBackSlashes", e);
}
throw new Exception();
}