Here you can find the source of deleteRecursive(File f)
Parameter | Description |
---|---|
file | a parameter |
private static final void deleteRecursive(File f) throws IllegalArgumentException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2011 Andrew Gvozdev 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 ww w. j a v a2 s.c om * Andrew Gvozdev - Initial API and implementation * James Blackburn (Broadcom Corp.) * Liviu Ionescu - bug 392416 *******************************************************************************/ import java.io.File; import org.eclipse.core.resources.ResourcesPlugin; public class Main { /** * Recursively delete a directory / file * * For safety this method only deletes files created under the workspace * * @param file */ private static final void deleteRecursive(File f) throws IllegalArgumentException { // Ensure that the file being deleted is a child of the workspace // root to prevent anything nasty happening if (!f.getAbsolutePath() .startsWith(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getAbsolutePath())) { throw new IllegalArgumentException("File must exist within the workspace!"); } if (f.isDirectory()) { for (File f1 : f.listFiles()) { deleteRecursive(f1); } } f.delete(); } }