NIO2

java7-NIO2 - 图1

java7-NIO2 - 图2

java7-NIO2 - 图3

java7-NIO2 - 图4

java7-NIO2 - 图5

java7-NIO2 - 图6

java7-NIO2 - 图7

  1. public class NioDemo {
  2. public static void main(String[] args) throws Exception {
  3. Path path = Paths.get("D:\\workspace\\consume\\consume\\d1");
  4. FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
  5. @Override
  6. public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
  7. Files.delete(dir);
  8. return FileVisitResult.CONTINUE;
  9. }
  10. @Override
  11. public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
  12. Files.delete(file);
  13. return FileVisitResult.CONTINUE;
  14. }
  15. };
  16. Files.walkFileTree(path, visitor);
  17. }
  18. }