Here you can find the source of delTree(File f)
Parameter | Description |
---|---|
f | root of tree to delete |
Parameter | Description |
---|---|
IOException | if an I/O error occurs |
public static void delTree(File f) throws IOException
//package com.java2s; /*//from ww w . j ava 2 s . c o m * Copyright 2005--2008 Helsinki Institute for Information Technology * * This file is a part of Fuego middleware. Fuego middleware is free * software; you can redistribute it and/or modify it under the terms * of the MIT license, included as the file MIT-LICENSE in the Fuego * middleware source distribution. If you did not receive the MIT * license with the distribution, write to the Fuego Core project at * fuego-core-users@googlegroups.com. */ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; public class Main { /** Delete directory tree. Deletes the * directory tree rooted at <code>f</code> including <code>f</code>. * * @param f root of tree to delete * @throws IOException if an I/O error occurs */ public static void delTree(File f) throws IOException { delTree(f, true, null); } /** Delete directory tree. Deletes the * directory tree rooted at <code>f</code>. The directory * <code>f</code> itself is deleted if <code>delRoot</code> is * <code>true</code>. * * @param f root of tree to delete * @param delRoot set to <code>true</code> to delete root. * @throws IOException if an I/O error occurs */ public static void delTree(File f, boolean delRoot) throws IOException { delTree(f, delRoot, null); } /** Delete directory tree. Deletes the * directory tree rooted at <code>f</code>. The directory * <code>f</code> itself is deleted if <code>delRoot</code> is * <code>true</code>. * * @param f root of tree to delete * @param fi filter that an entry must pass in order to be deleted * (<code>null</code> means all pass) * @param delRoot set to <code>true</code> to delete root. * @throws IOException if an I/O error occurs */ public static void delTree(File f, boolean delRoot, FilenameFilter fi) throws IOException { // First, delete children if (f.isDirectory()) { File[] entries = f.listFiles(); for (int i = 0; i < entries.length; i++) delTree(entries[i], true, fi); } // Then delete this node if (delRoot && (fi == null || fi.accept(f.getParentFile(), f.getName())) && !f.delete()) throw new IOException("Can't delete " + f); } }