Skip to content

Instantly share code, notes, and snippets.

@hacklschorsch
hacklschorsch / FileChangeNotifier.java
Last active July 15, 2019 22:12
Java observable that notifies on changes to a File using Java 7 NIO and a separate thread.
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.util.Observable;
import static java.nio.file.StandardWatchEventKinds.*;
/**
* FileChangeNotifier notifies its observers when @file has changed.
* It uses Java 7 NIO and runs in a separate thread (since the NIO call blocks).