Path dir = Paths.get("c:"++ File.separator +"images");
if (Files.exists(dir)) {
try {
Files.walkFileTree(dir, 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 e) throws IOException {
if (e == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;// 没找到继续找
} else {
throw e;
}
};
});
} catch (IOException e) {
}
}
java删除文件夹
最新推荐文章于 2022-05-28 10:27:14 发布