Here you can find the source of deleteDirectory(File dir)
public static void deleteDirectory(File dir) throws IOException
//package com.java2s; // modify it under the terms of the GNU General Public License import java.io.File; import java.io.IOException; public class Main { public static void deleteDirectory(File dir) throws IOException { deleteDirectory(dir, false);/*from w w w .j ava 2 s . c o m*/ } public static void deleteDirectory(File dir, boolean recurse) throws IOException { if (!dir.isDirectory()) return; File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].getName().equals(".") || files[i].getName().equals("..")) continue; else if (files[i].isDirectory() && recurse) deleteDirectory(files[i], recurse); else files[i].delete(); } dir.delete(); } }