Non-blocking (NIO) reading of lines

前端 未结 9 750
滥情空心
滥情空心 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:31

    NIO is typically used to do either direct memory access or block mediated bulk data transfers. It does do other things, but other features have more to do with blocking and non-blocking data access.

    As such, you might want to use NIO to grab the data quickly (or in a non-blocking manner); however, if you want to "read line by line" you would be better served by doing the line detection after NIO has read in the available data. This could easily be implemented by putting a "line reading" facade over the buffer that NIO just read.

提交回复
热议问题