Here you can find the source of deleteRecursively(File file)
Parameter | Description |
---|---|
file | the file or directory to be deleted |
true
iff deletion fully succeeded
@SuppressWarnings("ConstantConditions") public static boolean deleteRecursively(File file)
//package com.java2s; /*//from ww w . j av a 2 s . c om * Copyright (c) 2015 the original author or authors. * 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: * Etienne Studer & Don?t Csik?s (Gradle Inc.) - initial API and implementation and initial documentation */ import java.io.File; public class Main { /** * Deletes the given file or directory. In case of a directory, all its content is deleted recursively. * * @param file the file or directory to be deleted * @return <code>true</code> iff deletion fully succeeded */ @SuppressWarnings("ConstantConditions") public static boolean deleteRecursively(File file) { if (file.isDirectory()) { boolean success = true; File[] children = file.listFiles(); for (File child : children) { success &= deleteRecursively(child); } return success && file.delete(); } else { return file.delete(); } } }