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) throws IOException 

Method Source Code

//package com.java2s;
// modify it under the terms of the GNU General Public License

import java.io.File;

import java.io.IOException;

public class Main {
    public static void deleteDirectory(File dir) throws IOException {
        deleteDirectory(dir, false);/*from  w  w  w  .j  ava  2  s .  c o  m*/
    }

    public static void deleteDirectory(File dir, boolean recurse) throws IOException {
        if (!dir.isDirectory())
            return;

        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].getName().equals(".") || files[i].getName().equals(".."))
                continue;
            else if (files[i].isDirectory() && recurse)
                deleteDirectory(files[i], recurse);
            else
                files[i].delete();
        }

        dir.delete();
    }
}

Related

  1. deleteDirectory(File dir)
  2. deleteDirectory(File dir)
  3. deleteDirectory(File dir)
  4. deleteDirectory(File dir)
  5. deleteDirectory(File dir)
  6. deleteDirectory(File dir, boolean isInitialDelete)
  7. deleteDirectory(File dir, boolean isInitialDelete)