import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @description:
* @author: xz
* @create: 2022-07-31 10:58
*/
public class TestWalkFileTree {
public static void main(String[] args) throws IOException {
deleteMoreDirectory();
}
/**
* 删除多级目录
* */
private static void deleteMoreDirectory() throws IOException {
Files.walkFileTree(Paths.get("E:\\apache-tomcat-8.5.78-副本"), new SimpleFileVisitor<Path>() {
//进入文件夹之前
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
System.out.println("进入文件夹===>"+dir);
return super.preVisitDirectory(dir, attrs);
}
//遍历文件
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return super.visitFile(file, attrs);
}
//进入文件夹之后
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
System.out.println("退出文件夹===>"+dir);
Files.delete(dir);
return super.postVisitDirectory(dir, exc);
}
});
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://wwwxz.blog.csdn.net/article/details/126092285
内容来源于网络,如有侵权,请联系作者删除!