How to read a file line by line in Java 8?

In Java 8, I see a new method being added to the Files class, which can be used to read a file line by line in Java. Does it work for huge files? I mean, we can load the first 1000 lines, and then the second set of 1000 lines. I have a huge file with 1 GB, will it work?

Can anyone share a piece of code, how to use it?

+4
source share
2 answers

Does it work on huge files? [...] I have a huge file with 1 GB, will it work?

As far as I can see, it should work well for large files (but I have not tried):

try(Stream<String> lines = Files.lines(path)){
    lines.filter(...).map(...)....foreach(...);
}

I mean, we can load the first 1000 lines, and then the second set of 1000 lines.

- , Files.lines(, , BufferedReader, ).

+6

API ( )

. readAllLines, , , .

, , , .

0

Source: https://habr.com/ru/post/1599472/


All Articles