Java File Path Delete deleteDir(File dir)

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

Description

delete Dir

License

Apache License

Declaration

public static boolean deleteDir(File dir) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

public class Main {

    public static boolean deleteDir(File dir) throws IOException {
        if (null == dir || !dir.exists())
            return false;
        if (!dir.isDirectory())
            throw new IOException("\"" + dir.getAbsolutePath() + "\" should be a directory!");
        File[] files = dir.listFiles();
        boolean re = false;
        if (null != files) {
            if (files.length == 0)
                return dir.delete();
            for (File f : files) {
                if (f.isDirectory())
                    re |= deleteDir(f);/*  www  .j  a va2 s. c o m*/
                else
                    re |= deleteFile(f);
            }
            re |= dir.delete();
        }
        return re;
    }

    public static boolean isDirectory(File f) {
        if (null == f)
            return false;
        if (!f.exists())
            return false;
        if (!f.isDirectory())
            return false;
        return true;
    }

    public static boolean deleteFile(File f) {
        if (null == f)
            return false;
        return f.delete();
    }
}

Related

  1. deleteDir(File dir)
  2. deleteDir(File dir)
  3. deleteDir(File dir)
  4. deleteDir(File dir)
  5. deleteDir(File dir)
  6. deleteDir(File dir)
  7. deleteDir(File dir)
  8. deleteDir(File dir, boolean deleteRoot)
  9. deleteDir(File dir, boolean deleteSelf)