Reputation: 5215
Path path = Paths.get("D:/tmp/a/aa/aaa");
Files.delete(path);
path = Paths.get("D:/tmp/a/aa");
Files.delete(path);
Here is the exception i'm getting:
Exception in thread "main" java.nio.file.DirectoryNotEmptyException: D:\tmp\a\aa
at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:264)
at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
at java.nio.file.Files.delete(Files.java:1077)
at test.Test.main(Test.java:44)
though are no files/folders inside aa
folder.
This behavior is observed when i visited the folder using windows explorer(Here aa
) and moved to D:\
root directory.
If i close the explorer widow, this program is working fine.
I know windows sometimes locks the folders, even in that case the exception message java.nio.file.DirectoryNotEmptyException: D:\tmp\a\aa
seems to be wrong
Upvotes: 2
Views: 966
Reputation: 176
Another tip, use "/" instead of "\\" as Java is supposed to be platform independant while "/" is recognised on both linux and windows.
Upvotes: 2
Reputation: 5916
Yes the error message is wrong, but Windows will not let a file or folder be deleted it another process has a handle open on it. This cannot be fixed from Java.
Upvotes: 3