I just read a file whose size is 167MB and line number is 1884000. The method I use is BufferedReader
to get the effect of reading it in line.
What I noticed is that the process of reading the file is growing slower and slower as the current line number increased (In this case, it tooks me 3h30min to finish it).
I know using nio
may speed up this procedure, but I want to read the file in line.
My code is as below; could anyone give me some suggestions? Thanks a lot!
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);
}
}