Here you can find the source of deleteDirectory(File fileOrDir)
Parameter | Description |
---|---|
fileOrDir | The file or directory to be deleted. |
public static boolean deleteDirectory(File fileOrDir)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 Arapiki Solutions Inc. * 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:/* w ww .j a v a2 s. c om*/ * "Peter Smith <psmith@arapiki.com>" - initial API and * implementation and/or initial documentation *******************************************************************************/ import java.io.File; public class Main { /** * Delete a file system file or directory (and all the files and sub-directories it may * contain). * @param fileOrDir The file or directory to be deleted. * @return True or false, to indicate whether the deletion was successful. */ public static boolean deleteDirectory(File fileOrDir) { if (fileOrDir.isDirectory()) { String[] children = fileOrDir.list(); for (int i = 0; i < children.length; i++) { if (!deleteDirectory(new File(fileOrDir, children[i]))) { return false; } } } return fileOrDir.delete(); } }