Read a file while it's being written

前端 未结 2 1435
我在风中等你
我在风中等你 2021-01-25 05:55

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

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-25 05:59

    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.

提交回复
热议问题