Does BufferedReader.ready() method ensure that readLine() method does not return NULL?

The ready method tells us if the Stream is ready to be read.

Imagine your stream is reading data from a network socket. In this case, the stream may not have ended, because the socket has not been closed, yet it may not be ready for the next chunk of data, because the other end of the socket has not pushed any more data.

In the above scenario, we cannot read any more data until the remote end pushes it, so we have to wait for the data to become available, or for the socket to be closed. The ready() method tells us when the data is available.

Leave a Comment