public final class FileWatcher
extends java.lang.Object
New watches are added with the addWatch(Path, Runnable) method, which specifies the
task to execute when the file is modified.
This class is thread-safe.
| Constructor and Description |
|---|
FileWatcher()
Creates a new FileWatcher.
|
FileWatcher(java.util.function.Consumer<java.lang.Exception> exceptionHandler)
Creates a new FileWatcher.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addWatch(java.io.File file,
java.lang.Runnable changeHandler)
Watches a file, if not already watched by this FileWatcher.
|
void |
addWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
Watches a file, if not already watched by this FileWatcher.
|
static FileWatcher |
defaultInstance()
Gets the default, global instance of FileWatcher.
|
void |
removeWatch(java.io.File file)
Stops watching a file.
|
void |
removeWatch(java.nio.file.Path file)
Stops watching a file.
|
void |
setWatch(java.io.File file,
java.lang.Runnable changeHandler)
Watches a file.
|
void |
setWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
Watches a file.
|
void |
stop()
Stops this FileWatcher.
|
public FileWatcher()
public FileWatcher(java.util.function.Consumer<java.lang.Exception> exceptionHandler)
public static FileWatcher defaultInstance()
public void addWatch(java.io.File file,
java.lang.Runnable changeHandler)
throws java.io.IOException
file - the file to watchchangeHandler - the handler to call when the file is modifiedjava.io.IOExceptionpublic void addWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
throws java.io.IOException
file - the file to watchchangeHandler - the handler to call when the file is modifiedjava.io.IOExceptionpublic void setWatch(java.io.File file,
java.lang.Runnable changeHandler)
throws java.io.IOException
file - the file to watchchangeHandler - the handler to call when the file is modifiedjava.io.IOExceptionpublic void setWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
throws java.io.IOException
file - the file to watchchangeHandler - the handler to call when the file is modifiedjava.io.IOExceptionpublic void removeWatch(java.io.File file)
file - the file to stop watchingpublic void removeWatch(java.nio.file.Path file)
file - the file to stop watchingpublic void stop()
throws java.io.IOException
java.io.IOException