tsv文件 java_优秀有效的Java CSV / TSV阅读器

我想读大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();

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值