Java Delete Directory Recursively deleteDirectoryRecursivelyE(File dir)

Here you can find the source of deleteDirectoryRecursivelyE(File dir)

Description

delete Directory Recursively E

License

Apache License

Declaration

public static void deleteDirectoryRecursivelyE(File dir) 

Method Source Code


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

import java.io.*;

public class Main {
    public static void deleteDirectoryRecursivelyE(File dir) {
        if (!dir.isDirectory())
            throw new RuntimeException("Not a directory: " + dir.getAbsolutePath());

        for (File f : dir.listFiles()) {
            if (f.isDirectory()) {
                deleteDirectoryRecursivelyE(f);
            } else {
                if (!f.delete())
                    throw new RuntimeException("Failed to delete file: " + f.getAbsolutePath());
            }//from w w w .  j av a2s.  co  m
        }
        if (!dir.delete())
            throw new RuntimeException("Failed to delete directory: " + dir.getAbsolutePath());
    }
}

Related

  1. deleteDirectoryRecursive(File directory)
  2. deleteDirectoryRecursive(File f)
  3. deleteDirectoryRecursively(File rootFile)
  4. deleteDirectoryRecursively(File toDelete)
  5. deleteDirectoryRecursivly(File directory)
  6. deleteDirRecursive(File aDir)
  7. deleteDirRecursively(File dir)
  8. deleteDirRecursively(File directory)