simple-lines.txt
this
is
a
test
file
PrintFileContents.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | package io.nibs.java; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class PrintFileContents { public static void main(String args[]) throws IOException { final String fileName = "./test-files/simple-lines.txt"; Files.lines(Paths.get(fileName)) .forEach(System.out::println); } } |
console output
1 2 3 4 5 | this
is
a
test
file
|
If you are new to Java 8 Streams be sure to check out our Introduction to Streams