Java IO implementation of unix/linux “tail -f”

前端 未结 9 1858
我寻月下人不归
我寻月下人不归 2020-11-22 12:06

I\'m wondering what techniques and/or library to use to implement the functionality of the linux command \"tail -f \". I\'m essentially looking for a drop in add-on/replace

9条回答
  •  耶瑟儿~
    2020-11-22 12:30

    Here's a short story which you could use as a pointer:

    I've coded TailingInputStream at work for the very same reason. It basically uses File and refreshed its contents on demand and checked against internal buffer if it has changed significantly (4kB memory stamp IIRC) and then did what the tail -f does. A bit hacky, yes, but it works perfectly and doesn't mess with Threads or anything fancy like that - it's compatible all the way back to 1.4.2 at least.

    That said, it was a lot easier to do than ReverseInputStream which went from file's end to start and didn't die if the file was updated on the fly...

提交回复
热议问题