问题
I want to read a (log file being written continuously by an app)
Currently I have temp solution using RandomAccessFile (read mode)
Is there any other solution to this problem ?
回答1:
Java 7 has new API that allows listening to the file system events: http://java.dzone.com/news/how-watch-file-system-changes
If you are stuck with previous version of java use poling as described here: File changed listener in Java
回答2:
You probably could use FileInputStream
to read this file. The fact that another process/thread is writing to it should not be a problem, especially if it only appends data to the file.
来源:https://stackoverflow.com/questions/14799945/how-to-read-a-live-file-that-is-being-writen-by-another-writer-thread