Java Stream create from text file

Description

Java Stream create from text file


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 a  v a2  s. c o m*/
    }
  }
}



PreviousNext

Related