Suggestions/sample code for fileSystemWatcher in Java

后端 未结 5 564
[愿得一人]
[愿得一人] 2021-01-02 14:27

I am trying to build a fileSystemWatcher in java (similar to FileSystemWatcher in C#). Please suggest whether java has any built in framework capability for this or suggest/

5条回答
  •  感情败类
    2021-01-02 14:39

    I don't believe there's any inbuilt capability. You can always poll the directory in a thread, and watch for directory modification times etc. That's trivial, but I'm not sure how OSes differ in how they'll reflect directory changes in the directory meta data. If you have to keep track of a directory with a large number of files, any solutions based on polling may be quite heavyweight.

    I note this, which is a more optimal version for Windows (not that I know what platform you're on!)

提交回复
热议问题