ENTRY_DELETE: indicates that a directory or file is deleted.ENTRY_CREATE: indicates that a directory or file is created.All interfaces and classes in the Watch Service API can be found in the package, create a new WatchService object like this: WatchService watcher = FileSystems.getDefault().newWatchService() Then register this WatchService for a given directory like the following: Path dir = Paths.get("Path/To/Watched/Directory") ĭir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY) The register() method of the Path class takes a WatchService object and a varargs list of event types which the application needs to get notified. In this article, we’ll see how to use this API in the simplest form with a simple demo program. The Watch Service API is fairly simple to use, and relieves programmers from using third party libraries for files change monitoring. Java 7 adds a new feature for its NIO package called Watch Service API which allows applications monitoring directories and files for change events such as creation, deletion and modification.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |