App下載
首頁javastream_convertJava Stream - 如何將文件轉(zhuǎn)換為流

Java Stream - 如何將文件轉(zhuǎn)換為流

我們想知道如何將文件轉(zhuǎn)換為流。
import java.io.BufferedReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] argv) throws Exception {
    BufferedReader reader = Files.newBufferedReader(Paths.get("a.bat"), StandardCharsets.UTF_8);
    //BufferedReader's lines methods returns a stream of all lines
    reader.lines().forEach(System.out::println);
  }
}