How to monitor a folder for changes in java?

后端 未结 2 1775
逝去的感伤
逝去的感伤 2021-02-09 04:19

I have the below code for monitoring a folder for any changes in java:

    public class FolderWatcher
    {
    // public List events = new ArrayLis         


        
2条回答
  •  有刺的猬
    2021-02-09 05:15

    Why don't you store a metadata file in each folder (recursively), in that metadata file you can store file list and modified date and size of each file. Your thread should compare this metadata file in each folder with the current files present in the same. That is how you can detect any change within that folder.

    Remember you should do it recursively for each subfolder within that. And the metadata file should be updated with each scan. Hope this helps..

提交回复
热议问题