Java Files read text file to Stream

Description

Java Files read text file to 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   www .j  a  va  2s.  co  m
    }
  }
}



PreviousNext

Related