Java Path Remove nio removeDirectory(Path directory)

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

Description

remove Directory

License

Apache License

Declaration

public static void removeDirectory(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 removeDirectory(Path directory) throws IOException {
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
            @Override//ww w .  jav a  2  s  .com
            public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
                Files.delete(file);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
        });
    }
}

Related

  1. appendOrRemove(LinkedList paths, DirectoryStream ds)
  2. recursiveRemoveFolder(Path folderPath)
  3. removeDirectory(Path directory)
  4. removeDirectory(String pathToDir)
  5. removeDirectoryIfItIsEmpty(Path directoryToRemove)
  6. removeDriveLetter(Path path)