I am using a text file to store the serial port output. And now I want to put the contents of the file to an textArea in java. I have created a dedicated thread for file read operation. I need the thread to sleep when ther开发者_Go百科e is no data to read and thread should wake up automatically once data available for read in the file. In the thread I am using a while loop and using readLine() method for reading from file. But when data not available when readLine called in while loop the loop exits and thread terminates. Can anybody suggest how to implement this?
You can use FIFO pipe (man mkfifo
) and write the serial port output data to it instead of the file, or both into the FIFO and into the file (man tee
).
The reason why the loop exits is, as far as I understand, that you're hitting the end of file.
精彩评论