Here you can find the source of deleteDirectory(Path path)
public static void deleteDirectory(Path path) throws IOException
//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 path) throws IOException { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w.j ava 2 s . co m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { // try to delete the file anyway, even if its attributes // could not be read, since delete-only access is // theoretically possible Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { // directory iteration failed; propagate exception throw exc; } } }); } }