Java Delete Folder deleteFolderRecursively(File file)

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

Description

delete Folder Recursively

License

LGPL

Declaration

public static void deleteFolderRecursively(File file) 

Method Source Code

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

import java.io.File;

public class Main {
    public static void deleteFolderRecursively(File file) {
        try {//from ww w.j av  a 2s  . com
            File[] allFiles = file.listFiles();
            if (allFiles == null) {
                file.delete();
                return;
            }

            for (File f : allFiles) {
                if (f.isDirectory())
                    deleteFolderRecursively(f);
                else
                    f.delete();
            }
            file.delete(); // Make sure to delete the folder once we've cleared out its contents
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. deleteFolderContents(File folder)
  2. deleteFolderContents(File folder)
  3. deleteFolderIfEmpty(File f)
  4. deleteFolderRec(File dir)
  5. deleteFolderRecursive(File folder)
  6. deleteFolderRecursively(File folder)