Java File Path Delete deleteDir(File dir)

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

Description

delete Dir

License

Apache License

Declaration

static void deleteDir(File dir) 

Method Source Code


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

import java.io.File;

public class Main {
    static void deleteDir(File dir) {
        if (!dir.exists()) {
            return;
        }/* w w w  . ja  va  2  s .c  om*/
        for (File e : dir.listFiles()) {
            if (e.isDirectory())
                deleteDir(e);
            else
                delete(e);
        }
        delete(dir);
    }

    static void delete(File f) {
        boolean success = f.delete();
        String path = f.getAbsolutePath();
        if (success) {
            System.out.println("delete file : " + path);
        } else {
            throw new IllegalStateException("deleting file failed. " + path);
        }
    }
}

Related

  1. deleteContents(File dirPath, List failures)
  2. deleteContentsOnly(final String srcPath)
  3. deleteDataFiles(final Collection paths)
  4. deleteDb(String path)
  5. deleteDir(File delDir)
  6. deleteDir(File dir)
  7. deleteDir(File dir)
  8. deleteDir(File dir)
  9. deleteDir(File dir)