How can I follow a file like “Tail -f” does in Java without holding the file open (Prevent rename/delete)

前端 未结 3 901
离开以前
离开以前 2020-12-24 00:27

i\'d like to \"Tail -f\" a lot of logfiles from within a java app.

I\'ve gotten this to work by monitoring the size and last update and repeatedly opening the file a

3条回答
  •  萌比男神i
    2020-12-24 01:16

    In Linux you would not have a problem since the locking is only advisory. But in Windows things are different.
    This should depend on the mode that your logger (I assume log4j) opens the file to log.
    Looking in this answer for C# it seems that there is a parameter dwShareMode that can be used for this kind of sharing.

    I believe NIO would be the way to go. Look if dwShareMode parameter is available as part of NIO APIs

提交回复
热议问题