I have to read the tomcat log file,and after some time(for example:one hour) I will read the file again(just for the new added content),so I create the RandomAccessFile to recor
readLine()
strips EOL characters so you don't see it. There is no difference between EOF and EOL from its point of view which is troubling in your case. In addition to Peter's solution, you can try seeking one byte back after you read the line and check if it was EOL or not. Be careful about line ending style being used, though.
readLine consumes the newline character. You can't use it to determine if you have a complete line or not. You need to read one byte at a time and parse the line yourself.
Also you are not moving on the position when you get a valid line..