Java Delete Directory deleteDirectory(File dir)

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

Description

delete Directory

License

Open Source License

Declaration

public static void deleteDirectory(File dir) 

Method Source Code

//package com.java2s;
/*//from  w  ww.java2s .  c o m
 * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
 */

import java.io.*;

public class Main {
    public static void deleteDirectory(File dir) {
        if (dir.isDirectory()) {
            for (File f : dir.listFiles()) {
                if (f.isDirectory())
                    deleteDirectory(f);
                else
                    f.delete();
            }
            dir.delete();
        }
    }

    public static File[] listFiles(final File dir) {
        return listFilesWithExtension(dir, null);
    }

    public static File[] listFilesWithExtension(final File dir, final String ext) {
        return dir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return (ext != null) ? name.endsWith("." + ext) : true;
            }
        });
    }
}

Related

  1. deleteDirectory(File dir)
  2. deleteDirectory(File dir)
  3. deleteDirectory(File dir)
  4. deleteDirectory(File dir)
  5. deleteDirectory(File dir)