Class FileWatcher

java.lang.Object
net.mcreator.io.FileWatcher
All Implemented Interfaces:
Closeable, AutoCloseable

public class FileWatcher extends Object implements Closeable
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.

  • Constructor Details

    • FileWatcher

      public FileWatcher()
  • Method Details

    • addListener

      public void addListener(FileWatcher.Listener listener)
      Adds a listener to be notified when a file is changed.
      Parameters:
      listener - the listener to add
    • watchFolder

      public void watchFolder(File path)
      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 interface AutoCloseable
      Specified by:
      close in interface Closeable