Package net.mcreator.io
Class FileWatcher
java.lang.Object
net.mcreator.io.FileWatcher
- All Implemented Interfaces:
Closeable
,AutoCloseable
This class watches a directory for changes and notifies listeners when a file is created, deleted, or modified.
It uses the Java NIO WatchService API to monitor file system events.
The class is designed to be used in a generator context, where it can watch for changes in the generator's workspace.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(FileWatcher.Listener listener) Adds a listener to be notified when a file is changed.void
close()
void
watchFolder
(File path) Watches a folder for changes.
-
Constructor Details
-
FileWatcher
public FileWatcher()
-
-
Method Details
-
addListener
Adds a listener to be notified when a file is changed.- Parameters:
listener
- the listener to add
-
watchFolder
Watches a folder for changes. If the folder is not a directory, it will not be watched.The watch is not recursive, so only the specified folder will be watched, not its subdirectories!
- Parameters:
path
- the path to the folder to watch
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-