Listening for file system modifications

As of Java 1.7, the standard I/O API supports filing system notification events: in other words, it provides a means for you to ask the filing system to notify your program in the event of files being modified. This functionality can be useful in situations such as:

In Java, file notifications are provided via the Java WatchService API. Some caveats to be aware of include the following:

However, despite these restrictions, receiving filing system notifications via the WatchService API can be immensely useful when used with care. In the following sections we examine how to use the WatchService API in detail.