BufferedReader, detecting if there is text left to read

后端 未结 3 1969
盖世英雄少女心
盖世英雄少女心 2021-01-06 00:33

I\'m running a thread and everytime it runs, It should be checking to see if there is a new line to read from the BufferedReader although, it gets stuck waiting

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 01:10

    Why don't you check if it's ready to be read first? Just use bufferedReader.ready().

    Edit:

    ready won't tell you if you have a line ready, it will just tell you that there is something to be read. However, if you are expecting to get a line then this will work for you. The idea would be, first check if it's ready, and then read the line, in this way the thread won't be hanging there when there is absolutely nothing to read.

提交回复
热议问题