Java text file process by Stream
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Stream; public class Main { public static void main(String[] args) { Path path = Paths.get("Main.java"); try (Stream<String> lines = Files.lines(path)) { lines.forEach(System.out::println); } catch (IOException e) { e.printStackTrace();//from w w w .j av a2 s. c o m } } }