Here you can find the source of deleteDirectory(File directory)
public static void deleteDirectory(File directory) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static void deleteDirectory(File directory) throws IOException { if (!directory.exists()) { return; }/*from ww w .j av a 2s. co m*/ forceDelete(directory); if (!directory.delete()) { throw new IOException("Unable to delete directory " + directory + "."); } } private static void forceDelete(File file) throws IOException { if (file.isDirectory()) { File[] files = file.listFiles(); for (File child : files) { forceDelete(child); } deleteFile(file); } else { deleteFile(file); } } public static void deleteFile(File file) throws IOException { if (file == null) { return; } if (!file.delete()) { throw new IOException("Unable to delete file: " + file); } } }