Here you can find the source of deleteDir(File dir)
public static boolean deleteDir(File dir)
//package com.java2s; import java.io.File; public class Main { public static boolean deleteDir(File dir) { if (dir == null) return false; if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; }//from w w w. jav a 2 s. c o m } } // The directory is now empty so delete it return dir.delete(); } public static boolean deleteDir(String path) { if (path == null) return false; File file = new File(path); return deleteDir(file); } public static boolean delete(File file) { if (file == null) return false; return file.delete(); } public static boolean delete(String path) { if (path == null) return false; File file = new File(path); return file.delete(); } }