Here you can find the source of deleteDirectory(File directory)
Parameter | Description |
---|---|
directory | directory to delete |
Parameter | Description |
---|---|
IOException | in case deletion is unsuccessful |
public static void deleteDirectory(File directory) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 MadRobot.// w w w . j a va2 s. c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * Elton Kent - initial API and implementation ******************************************************************************/ import java.io.File; import java.io.IOException; public class Main { /** * Deletes a directory recursively. * * @param directory * directory to delete * @throws IOException * in case deletion is unsuccessful * @see FileUtils#recursiveDelete(File) */ public static void deleteDirectory(File directory) throws IOException { if (!directory.exists()) { return; } if (!directory.delete()) { String message = "Unable to delete directory " + directory + "."; throw new IOException(message); } } }