Here you can find the source of deleteRecursively(final Path path)
public static void deleteRecursively(final Path path) throws IOException
//package com.java2s; //License from project: Common Public 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 deleteRecursively(final Path path) throws IOException { deleteRecursively(path, true);/*from www.j a va 2s.c o m*/ } public static void deleteRecursively(final Path path, final boolean deleteSelf) throws IOException { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // Delete file Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { // Try to delete anyway Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc == null) { // Delete directory (unless self) if (deleteSelf || !dir.equals(path)) { Files.delete(dir); } return FileVisitResult.CONTINUE; } else { throw exc; } } }); } }