Skip to content
Advertisement

Java Read Large Text File With 70million line of text

I have a big test file with 70 million lines of text. I have to read the file line by line.

I used two different approaches:

JavaScript

and

JavaScript

Is there another approach that can make this task faster?

Advertisement

Answer

1) I am sure there is no difference speedwise, both use FileInputStream internally and buffering

2) You can take measurements and see for yourself

3) Though there’s no performance benefits I like the 1.7 approach

JavaScript

4) Scanner based version

JavaScript

5) This may be faster than the rest

JavaScript

it requires a bit of coding but it can be really faster because of ByteBuffer.allocateDirect. It allows OS to read bytes from file to ByteBuffer directly, without copying

6) Parallel processing would definitely increase speed. Make a big byte buffer, run several tasks that read bytes from file into that buffer in parallel, when ready find first end of line, make a String, find next…

Advertisement