Non-blocking (NIO) reading of lines

前端 未结 9 874
滥情空心
滥情空心 2020-12-31 07:01

I need to read a file line by line using java.nio, but nio doesn\'t have a method like readline() to read one, complete line at a time

9条回答
  •  没有蜡笔的小新
    2020-12-31 07:53

    simply use: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#lines-java.nio.file.Path-

    EDIT (humanreadable translation, regards to MeetTitan): Which means: use java.nio.file.Files.lines(Path) - it returns a Stream representing the lines of the file. It's an method provided by the Java API. One could consult the Javadoc in order to see the details. The most relevant information is therefore: Files.lines() exists since Java 1.8. Use it.

提交回复
热议问题