pie154
pie154

Reputation: 613

Java Folder Monitor for creation/deletion/etc?

Is there a way to monitor folders in java to see when they are updated, ie file created, deleted, renamed,etc. And also is there any way to set it that it only looks for files that begin with a certain prefix, ie img?

Upvotes: 2

Views: 3348

Answers (3)

Sajad Bahmani
Sajad Bahmani

Reputation: 17469

You can use inotify-java API that provides an event-based mechanism for monitoring Linux file system events using the inotify interface provided by glibc (versions 2.4 and up) and the Linux kernel, starting from 2.6.13. Features Simple, easy to use feature-complete support for inotify Low memory footprint API uses blocking calls yielding low CPU usage

Upvotes: 0

Joachim Sauer
Joachim Sauer

Reputation: 308239

In Java 7 there is a WatchService API as part of NIO2. For earlier Java versions there's no pure Java solution except for manual polling.

Upvotes: 5

Brian Agnew
Brian Agnew

Reputation: 272397

See my answer to a similar question.

The mechanisms detailed won't filter on a file name/type. You'll have to do that alongside the suggested solutions.

Upvotes: 4

Related Questions