1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| package com.redisc;
import lombok.extern.slf4j.Slf4j;
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes;
@Slf4j(topic = "c.Test") public class Run {
public static void main(String[] args) throws IOException { m1(); }
private static void m1() throws IOException { Files.walkFileTree(Paths.get("src/main"), new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { System.out.println("进入====>" + dir); Files.delete(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); } }); }
}
|