How to read a live file - that is being writen by another writer thread

依然范特西╮ 提交于 2019-12-12 01:43:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!