1933 views.
package com.learnbyexamples.streams;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class E005_FileIntoStreamLines {
public static void main(String[] args) {
//Files.lines convert files into Stream<String>
try (Stream<String> lines = Files.lines(Paths.get("names.txt"))) {
//Iterate and Print all lines.
lines.forEach(System.out::println);
}
catch(Exception e) {
e.printStackTrace();
}
}
}