Monitor subfolders with a Java watch service

后端 未结 3 2139
小蘑菇
小蘑菇 2020-12-06 01:44

I am using watchKey to listen for a file change in a particular folder.

Path _directotyToWatch = Paths.get(\"E:/Raja\");
WatchService watcherSvc         


        
3条回答
  •  醉梦人生
    2020-12-06 02:18

    I know this is ugly, hopefully somebody has a better answer but you can create a list of every file in every subfolder and there last modified times.

    When you receive ENTRY_CREATE or ENTRY_DELETE compare the folder to your list to figure out which file was changed

    When you receive a ENTRY_MODIFY compare the last modified times.

    Remember to update your list.

提交回复
热议问题