我想读大CSV和TSV(制表符分隔)文件有关1000000行或更多。现在我试着用来读一个TSV包含~2500000行opencsv,但是它给我扔了一个java.lang.NullPointerException。它适用于TSV带~250000线的较小文件。因此,我想知道是否还有其他Libraries支持读取Large
CSV和TSVFiles的文件。你有什么想法?
每个对我的代码感兴趣的人(我将其缩短,因此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();
}