Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BufferedReader, detecting if there is text left to read

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 for a line to exist, thus halting the entire code.

if((inputLine = bufferedReader.readLine()) != null){
                System.out.println(inputLine);
                JOptionPane.showMessageDialog(null, inputLine);
}

Is there a way to better check if there is text in a BufferedReader to be read?

like image 577
user1729831 Avatar asked Nov 28 '12 01:11

user1729831


1 Answers

No, there's no easy way to do that. BufferedReader has a ready call, but that only applies to the read calls, not the readLine call. If you really want a readLine that's guaranteed not to block, you must implement it yourself using read and maintaining a char buffer yourself.

like image 167
Keith Randall Avatar answered Sep 19 '22 22:09

Keith Randall