Java Delete Directory Recursively deleteDirectoryRecursively(File rootFile)

Here you can find the source of deleteDirectoryRecursively(File rootFile)

Description

Recursive function to delete Directory having content.

License

Apache License

Parameter

Parameter Description
rootFile a parameter

Declaration

public static void deleteDirectoryRecursively(File rootFile) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    /**/* w ww. j a v a 2s . c o m*/
     * Recursive function to delete Directory having content.
     * @param rootFile
     */
    public static void deleteDirectoryRecursively(File rootFile) {
        File[] files = rootFile.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isFile()) {
                    file.delete();
                } else if (file.isDirectory()) {
                    deleteDirectoryRecursively(file);
                }
            }
        }
        rootFile.delete();
    }
}

Related

  1. deleteDirectoryRecursive(File directory)
  2. deleteDirectoryRecursive(File f)
  3. deleteDirectoryRecursively(File toDelete)
  4. deleteDirectoryRecursivelyE(File dir)
  5. deleteDirectoryRecursivly(File directory)
  6. deleteDirRecursive(File aDir)