Here you can find the source of deleteDir(File f)
public static boolean deleteDir(File f)
//package com.java2s; /*/*from ww w . ja v a 2 s . co m*/ Copyright (C) 2012 The Stanford MobiSocial Laboratory Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.io.*; public class Main { public static boolean deleteDir(File f) { if (f.isDirectory()) { String[] children = f.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(f, children[i])); if (!success) { System.err.println("warning: failed to delete file " + f); return false; } } } // The directory is now empty so delete it return f.delete(); } public static void deleteDir(String path) { if (path == null) return; File f = new File(path); if (f.exists()) { boolean success = deleteDir(f); warnIf(!success, "Unable to delete file: " + f.getPath()); } else warnIf(true, "Sorry, can't delete path because it doesn't even exist: " + path); } public static void warnIf(boolean b, String message) { if (b) { System.err.println("REAL WARNING: " + message + "\n"); // Thread.dumpStack(); breakpoint(); } } public static void breakpoint() { // permanent breakpoint } }