Java Recursive Delete recursiveDelete(File file)

Here you can find the source of recursiveDelete(File file)

Description

Delete a file and all its descendants, indicating success or failure.

License

Apache License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
IOException an exception

Return

true if this succeeds, or false if one or more files or directories can't be deleted.

Declaration

public static boolean recursiveDelete(File file) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

public class Main {
    /**//from  w  w w .j a v  a  2 s  .  co  m
     * Delete a file and all its descendants, indicating success or
     * failure. 
     * @param file
     * @throws IOException
     * @return true if this succeeds, or false if one or more files
     *      or directories can't be deleted. 
     */
    public static boolean recursiveDelete(File file) throws IOException {
        boolean success = true;
        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                if (!recursiveDelete(child)) {
                    success = false;
                }
            }
        }
        if (!file.delete()) {
            success = false;
        }
        return success;
    }
}

Related

  1. recursiveDelete(File file)
  2. recursiveDelete(File file)
  3. recursiveDelete(File file)
  4. recursiveDelete(File file)
  5. recursiveDelete(File file)
  6. recursiveDelete(File file)
  7. recursiveDelete(File file)
  8. recursiveDelete(File file, boolean deleteParentFile)
  9. recursiveDelete(File fileOrDir)