How should I read from a buffered reader?

前端 未结 9 967
無奈伤痛
無奈伤痛 2020-12-06 08:26

I have the following example of reading from a buffered reader:

while ((inputLine = input.readLine()) != null) {
   System.out.println(\"I got a message from         


        
9条回答
  •  温柔的废话
    2020-12-06 09:03

    The reader's readLine() will return a string value when it has something read, an empty string when there isn't anything yet, and null when the connection is closed.

    I would recommend wrapping a try/catch around your block of code with the IO function and handle errors appropriately.

提交回复
热议问题