Java Delete File Recursively deleteRecursive(final File file)

Here you can find the source of deleteRecursive(final File file)

Description

Deletes a file or directory.

License

Open Source License

Parameter

Parameter Description
file file to be deleted

Return

true if all the files where deleted successfully.

Declaration

public static boolean deleteRecursive(final File file) 

Method Source Code


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

import java.io.File;

public class Main {
    /**// www  .jav a  2 s.  c om
     * Deletes a file or directory.
     * If the file is a directory it recursively deletes it. 
     * @param file file to be deleted
     * @return true if all the files where deleted successfully.
     */
    public static boolean deleteRecursive(final File file) {
        boolean result = true;
        if (file.isDirectory()) {
            for (final File inner : file.listFiles()) {
                result &= deleteRecursive(inner);
            }
        }
        return result & file.delete();
    }
}

Related

  1. deleteRecursive(File src)
  2. deleteRecursive(File src, List excludes)
  3. deleteRecursive(File toDelete)
  4. deleteRecursive(File toDelete)
  5. deleteRecursive(final File dir)
  6. deleteRecursive(final File file)
  7. deleteRecursive(final File file)
  8. deleteRecursive(final File file, final boolean collect)
  9. deleteRecursiveDir(File directory)