我刚刚读取了一个大小为167MB,行数为1884000的文件。我使用的方法是
我的代码如下,请问有什么建议吗?非常感谢!
BufferedReader
按行读取文件。但我发现随着当前行号的增加,读取文件的过程变得越来越慢(在这种情况下,读完整个文件耗时3小时30分钟)。虽然我知道使用nio
可以加速这个过程,但我想继续按行读取文件。我的代码如下,请问有什么建议吗?非常感谢!
String htmlContentPath = html.getAbsolutePath();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(htmlContentPath)));
String line = null;
int cnt = 0;
while((line = reader.readLine()) != null) {
this.proc(line);
if((cnt++ % 2000) == 0) {
logger.info("current line number:\t"+cnt);
}
}
proc(line)
是什么作用?它会随着运行时间的增长而变慢吗? - Michael Myersthis.proc(line)
吗? - kevmo314Channel
会更快。 - user207421