Java Path Delete nio recursiveDelete(Path directory)

Here you can find the source of recursiveDelete(Path directory)

Description

recursive Delete

License

Apache License

Declaration

public static void recursiveDelete(Path directory) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

public class Main {
    public static void recursiveDelete(Path directory) throws IOException {
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
            @Override//from w w w. j  av a 2 s. c o  m
            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 {

                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
        });
    }
}

Related

  1. deleteTreeBelowPath(Path startHerePath)
  2. doDelete(@Nonnull Path path)
  3. forceDelete(Path path)
  4. optimisticDelete(Path path)
  5. readAndDelete(final Path p)
  6. recursiveDelete(Path path)
  7. recursiveDelete(Path pathToBeDeleted)
  8. recursiveDeleteDirectory(Path dir)
  9. recursiveDeleteOnShutdownHook(final Path path)