Here you can find the source of deleteDirectory(File dir)
public static void deleteDirectory(File dir)
//package com.java2s; /*//from w ww.java2s . c o m * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt */ import java.io.*; public class Main { public static void deleteDirectory(File dir) { if (dir.isDirectory()) { for (File f : dir.listFiles()) { if (f.isDirectory()) deleteDirectory(f); else f.delete(); } dir.delete(); } } public static File[] listFiles(final File dir) { return listFilesWithExtension(dir, null); } public static File[] listFilesWithExtension(final File dir, final String ext) { return dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return (ext != null) ? name.endsWith("." + ext) : true; } }); } }