user1534046
user1534046

Reputation: 1

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

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 ?

Upvotes: 0

Views: 737

Answers (2)

AlexR
AlexR

Reputation: 115338

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

Upvotes: 1

Mikhail Vladimirov
Mikhail Vladimirov

Reputation: 13890

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.

Upvotes: 0

Related Questions