Here you can find the source of deleteFolder(File path)
public static void deleteFolder(File path)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . ja va 2 s. c o m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.File; public class Main { private final static int MAX_RETRY = 5; public static void deleteFolder(File path) { if (path.isDirectory()) { for (File file : path.listFiles()) { file.delete(); } path.delete(); } } public static void delete(File file) { if (file.exists()) { for (int i = 0; i < MAX_RETRY; i++) { if (file.delete()) { i = MAX_RETRY; } else { try { Thread.sleep(1000); // sleep a second } catch (InterruptedException e) { // don't need to catch this } } } } } }