Java File Path Delete deleteDir(File dir)

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

Description

Recursively delete a directory and all its contents.

License

Open Source License

Parameter

Parameter Description
dir The directory to delete.

Return

true if and only if the directory is successfully deleted; false otherwise

Declaration

public static boolean deleteDir(File dir) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**/*www.  ja v a  2 s. co m*/
     * Recursively delete a directory and all its contents.
     * 
     * @param dir The directory to delete.
     * @return <code>true</code> if and only if the directory is successfully deleted; <code>false</code> otherwise
     */
    public static boolean deleteDir(File dir) {
        if (!dir.isDirectory()) {
            throw new IllegalArgumentException(dir + " does not exist or is not a directory");
        }
        File[] contents = dir.listFiles();
        for (File file : contents) {
            if (file.isDirectory()) {
                deleteDir(file);
            } else {
                file.delete();
            }
        }
        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)