I was using Java NIO Files.lines method but i was curious to know the code so dig little bit further then i see some FileChannel of nio package. my digging took me to buffered reader it seems like there nio is using io which is supposed to be blocking.
I was trying to read file for my webflux project reactor code but it seems like it could have some blocking in it.
BufferedReader.readLine()
is a blocking method. Did you think that all java.nio methods were non-blocking? Only some are non-blocking, i.e. just those that are explicitly documented as being non-blocking. All the others are blocking. In particular, you ask about Files.lines
. That returns a Stream
of lines. It uses the blocking method readLine()
internally, but it doesn't read all the lines in the file when you call it. It only reads each line when you make a terminal operation on the returned Stream.