The Java.nio.file package did not detect directory changes
want to detect the file that is writing to the directory, so I think a Java NIO package is more appropriate. However, I’ve run their test code ( https://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java )
It will only detect file changes made by the machine running the script.
That is, we have multiple servers running and they share many installed drives. If I log in to one of these servers, run the test code, log in to the same machine again through another terminal and change the directory I’m watching, those changes will be detected. However, if I log in to a different server, these changes do not occur. Is this a fundamental question for NIO? Should I use something else in this case? Or is there a workaround?
It’s kind of trying to warn you:
If a watched file is not located on a local storage device then it is
implementation specific if changes to the file can be detected. In
particular, it is not required that changes to files carried out on
remote systems be detected.
I’m afraid you’ll need to poll manually on a regular basis.