user2396426
user2396426

Reputation: 71

Get information about changed file in Java

I'm trying to monitor files in java. When a file modification will happen I want to know:

  1. Which process did the change.
  2. What has changed.

Also, I know that there is a way to change the "last modified date" in a file, so I want to check if someone has changed that field.

I tried "commons.io", "DefaultFileMonitor" and "WatchService", but all the information I could get from them was if a change has occurred and the file that was changed.

Upvotes: 0

Views: 136

Answers (2)

Crazyjavahacking
Crazyjavahacking

Reputation: 9677

I am pretty sure you cannot do that. Neither OS nor Java is storing such information. Maybe using some kernel calls.

Upvotes: 0

Joseph Larson
Joseph Larson

Reputation: 9058

Unless you're on a weird OS I know absolutely nothing about, you would need to use some mechanism you implement to track who is changing your file. The OS doesn't keep track of that. It also doesn't track what has changed.

So I don't believe you can do #1 unless you can get every process that MIGHT change the file to track that it did a change.

You could do #2 if you kept copies of the file then do a comparison.

Upvotes: 1

Related Questions