Here you can find the source of deleteDirectory(File directory)
public static void deleteDirectory(File directory)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.*; public class Main { public static void deleteDirectory(File directory) { if (directory != null) { deleteInDirectory(directory); directory.delete();/*from w w w . j a va 2s .co m*/ } } public static void deleteInDirectory(File directory) { if (directory != null) { deleteInDirectoryApartFrom(directory); } } public static void deleteInDirectoryApartFrom(File directory, String... apartFrom) { if (directory != null) { Set<String> excluded = new HashSet<String>(Arrays.asList(apartFrom)); for (File file : directory.listFiles()) { if (!excluded.contains(file.getName())) { if (file.isDirectory()) { deleteInDirectory(file); } file.delete(); } } } } }