0

How to monitor a file updated (file is actual.txt below)? But I just want to monitor the link folder.

ln -s ../actual.txt link

    Path path = Paths.get(".");

    WatchService watchService =  path.getFileSystem().newWatchService();
    path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
    WatchKey watchKey = null;
    while (true) {
        watchKey = watchService.poll(10, TimeUnit.MINUTES);
        if(watchKey != null) {
            watchKey.pollEvents().stream().forEach(event -> System.out.println(event.context()));
        }
        watchKey.reset();
    }

But this code is not work.

2
  • Update file actual.txt , but monitor folder where link exists
    – Glaha
    Commented Apr 16, 2020 at 6:25
  • If monitor the directory of actual.txt , is ok , but I just want to monitor link file. How to do ?
    – Glaha
    Commented Apr 16, 2020 at 6:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.