Interface FileWatchService

  • All Known Implementing Classes:
    StandardFileWatchService

    public interface FileWatchService
    A service that watches files or directories for changes and notifies registered listeners.

    This interface provides methods to register listeners for specific files or directories, specifying the types of events the listener is interested in. When a watched file or directory experiences an event (e.g., creation, modification, deletion), the associated listeners are notified.

    Example Usage

    
     // Example 1: Watching a single file with a single listener and specific event kinds
     FileWatchService watchService = ...; // implementation instance
     File fileToWatch = new File("/path/to/file.txt");
     FileChangedListener listener = event -> System.out.println("File changed: " + event.getFile());
    
     watchService.watch(fileToWatch, listener, FileChangedEvent.Kind.MODIFIED);
    
     // Example 2: Watching a directory with multiple listeners and all event kinds
     File dirToWatch = new File("/path/to/directory");
     List<FileChangedListener> listeners = Arrays.asList(
         event -> System.out.println("Listener 1 triggered: " + event),
         event -> System.out.println("Listener 2 triggered: " + event)
     );
    
     watchService.watch(dirToWatch, listeners); // All kinds by default
     
    Since:
    1.0.0
    Author:
    Mercy