Java Delete Tree delTree(File file)

Here you can find the source of delTree(File file)

Description

Delete a directory tree recursively.

License

Open Source License

Parameter

Parameter Description
file start point for deletion -- not itself deleted

Declaration

public static void delTree(File file) 

Method Source Code

//package com.java2s;
/*//  w w w  .  java 2 s .c  o m
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description: 
 *
 */

import java.io.*;

public class Main {
    /** Delete a directory tree recursively.
     * <p> 
     * Does not delete file.
     * @param file start point for deletion -- not itself deleted
     */
    public static void delTree(File file) {
        File[] files = file.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    delTree(files[i]);
                }
            }
        }
        files = file.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                files[i].delete();
            }
        }
    }
}

Related

  1. delTree(File directory)
  2. deltree(File directory)
  3. delTree(File f)
  4. delTree(File file)
  5. delTree(File file)
  6. delTree(File file)
  7. delTree(File file)
  8. delTree(File file)
  9. delTree(File root)