3 ms·
There is a utility method `Files.readAllLines` [1] (even since Java 7) which gives you a List<String>. Since Java 8 there is even a lazy variant `Files.lines()`
by noobymatze 9y ago
There is a utility method `Files.readAllLines` [1] (even since Java 7) which gives you a List<String>. Since Java 8 there is even a lazy variant `Files.lines()` [2], which returns a Stream<String>. Though you gotta be a bit careful with that last one and be sure to close the underlying reader, as mentioned in the docs.
I get your sentiment though.
[1]: https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#readAllLines(java.nio.file.Path,%20java.nio.charset.Charset) https://docs.oracle.com/javase/7/docs/api/java/nio/file/File...
[2]: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#lines-java.nio.file.Path-java.nio.charset.Charset- https://docs.oracle.com/javase/8/docs/api/java/nio/file/File...