Java Delete Tree deleteTree(final File file)

Here you can find the source of deleteTree(final File file)

Description

This method can be used to perform a deep deletion of a directory structure starting at, and including the directory provided.

License

Open Source License

Parameter

Parameter Description
file the directory to be deep deleted

Declaration

public static void deleteTree(final File file) 

Method Source Code


//package com.java2s;
import java.io.File;

public class Main {
    /**//from   w  w w  .java2  s . co m
     * This method can be used to perform a deep deletion of a directory structure starting at, and including the
     * directory provided.
     * 
     * @param file
     *            the directory to be deep deleted
     */
    public static void deleteTree(final File file) {
        if (file != null) {
            if (file.isDirectory()) {
                String[] children = file.list();
                for (String child : children) {
                    File childFile = new File(file, child);
                    deleteTree(childFile);
                }
            }
            file.delete();
        }
    }
}

Related

  1. deleteTree(File dir)
  2. deleteTree(File dir)
  3. deleteTree(File f)
  4. deleteTree(File file, boolean check)
  5. delTree(File dir)
  6. delTree(File dir)
  7. delTree(File dir, boolean deleteDirItSelf)
  8. deltree(File directory)