我正在尝试读取大约行或更多行的大文件CSV
和TSV
(制表符分隔的)文件。1000000
现在我试图用 读取TSV
包含~2500000
行opencsv
,但它抛出了一个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();
}