文件变化监视 java.nio.file.WatchService

    xiaoxiao2026-05-01  7

    WatchKey java.nio.file.Path. register(WatchService watcher, Kind<?>... events) throws IOException 为该文件注册watch service。 Registers the file located by this path with a watch service.  WatchKey java.nio.file.WatchService. take() throws InterruptedException 检索并移除下一个watch key。若没有可检索的则阻塞。 Retrieves and removes next watch key, waiting if none are yet present. List<WatchEvent<?>> java.nio.file.WatchKey. pollEvents() 检索并移除所有该watch key Retrieves and removes all pending events for this watch key, returning a List of the events that were retrieved.  Kind<?> java.nio.file.WatchEvent. kind() 返回事件种类 Returns the event kind. String java.nio.file.WatchEvent.Kind. name() 返回事件种类的名字。 Returns the name of the event kind. ? java.nio.file.WatchEvent. context() 返回事件发生的环境,简单讲就是不带路径的文件名。 Returns the context for the event. 
    最新回复(0)