简体   繁体   中英

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?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM