How to read from files with Files.lines(…).forEach(…)?

前端 未结 5 563
不思量自难忘°
不思量自难忘° 2020-12-03 07:53

I\'m currently trying to read lines from a text only file that I have. I found on another stackoverflow(Reading a plain text file in Java) that you can use Files.lines(..).f

5条回答
  •  星月不相逢
    2020-12-03 08:35

    With Java 8, if file exists in a classpath:

    Files.lines(Paths.get(ClassLoader.getSystemResource("input.txt")
                        .toURI())).forEach(System.out::println);
    

提交回复
热议问题