Here you can find the source of deleteDir(File dir)
public static void deleteDir(File dir) throws IOException
//package com.java2s; //License from project: Mozilla Public License import java.io.File; 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 { private static final SimpleFileVisitor<Path> nukeVisitor = new SimpleFileVisitor<Path>() { private FileVisitResult delete(Path file) throws IOException { Files.delete(file);//from w w w . jav a 2 s . com return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { return delete(file); } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return delete(file); } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return delete(dir); } }; public static void deleteDir(File dir) throws IOException { Files.walkFileTree(dir.toPath(), nukeVisitor); } }