Java File Path Delete deleteDir(File dir)

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

Description

delete Dir

License

Open Source License

Declaration

public static boolean deleteDir(File dir) 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.IOException;

public class Main {
    public static boolean deleteDir(File dir) {
        if (dir == null)
            return false;
        File candir;/*from w w w . j av a  2s . c o  m*/
        try {
            candir = dir.getCanonicalFile();
        } catch (IOException e) {
            return false;
        }
        if (!candir.equals(dir.getAbsoluteFile()))
            return false;
        File files[] = candir.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                boolean deleted = !file.delete();
                if (deleted && file.isDirectory())
                    deleteDir(file);
            }

        }
        return dir.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)
  9. deleteDir(File dir)