frostymarvelous
frostymarvelous

Reputation: 2805

Detect When a file is accessed/read with java

What I am trying to accomplish is detect whenever a file is read. Basically, it is going to be a sort of on-access scanner.

After searching google and SO, the only things I come up with are detecting file modifications (file change notification) using Jnotify, java.nio.file etc.

Is this currently possible in java, if not, is it possible in windows? Does windows give any way of accessing this? If yes, I do not mind coding a library in C or C++. I would love a cross-platform solution, but a windows only solution would also be great.

Cheers.

Upvotes: 3

Views: 1079

Answers (2)

pajton
pajton

Reputation: 16226

This is exactly the reason JNotify and other such libraries exists. For instance, JNotify uses WinAPI mechanisms to check for file notifications, which you would have to use anyway if you dediced to write a library.

Use JNotify or any other Java library that provides file notification services.

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168825

Perhaps look to Java 7 & NIO. See Watching a Directory for Changes for more details.

Upvotes: 1

Related Questions