Here you can find the source of deleteDir(File dir)
public static boolean deleteDir(File dir) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { public static boolean deleteDir(File dir) throws IOException { if (null == dir || !dir.exists()) return false; if (!dir.isDirectory()) throw new IOException("\"" + dir.getAbsolutePath() + "\" should be a directory!"); File[] files = dir.listFiles(); boolean re = false; if (null != files) { if (files.length == 0) return dir.delete(); for (File f : files) { if (f.isDirectory()) re |= deleteDir(f);/* www .j a va2 s. c o m*/ else re |= deleteFile(f); } re |= dir.delete(); } return re; } public static boolean isDirectory(File f) { if (null == f) return false; if (!f.exists()) return false; if (!f.isDirectory()) return false; return true; } public static boolean deleteFile(File f) { if (null == f) return false; return f.delete(); } }