I followed the Watching a Directory for Changes Java7 nio2 tutorial to recursively monitor the entire contents of a directory using the code sample WatchDir.java.
While this works well on Linux and Mac, on Windows (tested on Vista and 7), trying to delete nested, watched folders using Windows Explorer fails with a message akin to "Access Denied: You need permission to perform this action" when a file exists in one of the nested directories.
For example, if I watch a nested folder tree in Windows:
-- Folder A
-- Folder A1
-- File F
and try to delete Folder A, I get the said Access Denied error. However, it works fine if I:
- Delete Folder A1 then delete Folder A
- Delete File F then delete Folder A
Is there a way to use the nio2 WatchService to recursively watch a nested directory, but not act as though a program is accessing nested files?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…