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

前端 未结 4 1444
既然无缘
既然无缘 2020-11-30 12:20

I have such code to read a text file using BufferedReader:

BufferedReader reader=null;
    try {
        reader = new BufferedReader(new FileRea         


        
4条回答
  •  悲哀的现实
    2020-11-30 13:15

    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.

提交回复
热议问题