I need to read a file line by line using java.nio
, but nio
doesn't have a method like readline()
to read one, complete line at a time. What solutions are there?
I understand you guys don't like limitations, but in case the one asking don't have access to IO package or not allowed to import it for some reason the top answer is not helpful...
Two ways to do it completely IO free:
java.nio.file.Files.lines
,
Returns a stream of lines, which is part of .util package and not .io package like bufferedReader.
java.nio.file.Files.readAllLines
,
Returns a collection of lines which is iterable.
Proceed to use an iterator
orfor each
to extract a single line.
cheers
Why? NIO doesn't support reading lines. You can read millions of lines a second with BufferedReader.readLine().
I suggest that is sufficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With