I need to read a large text file of around 5-6 GB line by line using Java.
How can I do this quickly?
Once Java 8 is out (March 2014) you'll be able to use streams:
try (Stream lines = Files.lines(Paths.get(filename), Charset.defaultCharset())) {
lines.forEachOrdered(line -> process(line));
}
Printing all the lines in the file:
try (Stream lines = Files.lines(file, Charset.defaultCharset())) {
lines.forEachOrdered(System.out::println);
}