Monitor subfolders with a Java watch service

后端 未结 3 2142
小蘑菇
小蘑菇 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:27

    The reason you are only seeing an event for "E:/Raja/Test" and not "E:/Raja/Test/Foo.txt" (for example) is that you've only registered the "E:/Raja" directory with the service. This means you will see events on the directory and its immediate members. The "E:/Raja/Test" is a member of the directory, and you are getting events to say that is has been changed ... when files are added to it.

    The solution is to register all of subdirectories of "E:/Raja" as well ... going as far down the directory hierarchy as you need to go.

提交回复
热议问题