Java Directory Delete nio deleteDirectory(Path directory)

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

Description

delete Directory

License

Open Source License

Declaration

public static void deleteDirectory(Path directory) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public class Main {
    public static void deleteDirectory(Path directory) throws IOException {
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
            @Override//from   w  w w.j  a  v 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. deleteDirectory(final File directory)
  2. deleteDirectory(final Path dir, final int maxDepth)
  3. deleteDirectory(Path dir)
  4. deleteDirectory(Path directory)
  5. deleteDirectory(Path directory)
  6. deleteDirectory(Path directory)
  7. deleteDirectory(Path dirToDelete)
  8. deleteDirectory(Path path)
  9. deleteDirectory(String path)