How do you continuously read a file in Java?

前端 未结 4 1063
野的像风
野的像风 2020-12-17 14:36

I\'m trying to figure out how to continuously read a file and once there is a new line added, output the line. I\'m doing this using a sleep thread however it just seems to

4条回答
  •  盖世英雄少女心
    2020-12-17 15:16

    If you're planning to implement this on a reasonable sized application where multiple objects might be interested in processing the new lines coming to the file, you might want to consider the Observer pattern.

    The object reading from the file will notify each object subscribed to it as soon as a line has been processed. This will allow you to keep logic well separated on the class where it's needed.

提交回复
热议问题