I am trying to walk the file tree and delet all files/directories. The code is below:
Files.walkFileTree(metricPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir,
IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw exc;
}
}
});
}
This code is run in between unit tests, each of which is generating a separate file, in the form folder1/folder2/file
. When I try to walk that tree, The DirectoryNotEmptyException
is thrown when folder1 attempts to be deleted, although it is clearly empty...