Java Delete File Recursively deleteRecursively(File file)

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

Description

delete Recursively

License

LGPL

Declaration

public static boolean deleteRecursively(File file) 

Method Source Code


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

import java.io.File;

public class Main {
    public static boolean deleteRecursively(File file) {
        if (file.isDirectory()) {
            boolean success = true;
            for (File child : file.listFiles()) {
                if (!deleteRecursively(child)) {
                    success = false;//from ww w. j  ava2 s.  c om
                }
            }
            if (success) {
                return file.delete();
            } else {
                return success;
            }
        } else if (file.isFile()) {
            return file.delete();
        } else {
            // Does not exist
            return false;
        }
    }
}

Related

  1. deleteRecursively(File file)
  2. deleteRecursively(File file)
  3. deleteRecursively(File file)
  4. deleteRecursively(File file)
  5. deleteRecursively(File file)
  6. deleteRecursively(File file)
  7. deleteRecursively(File file)
  8. deleteRecursively(File file)
  9. deleteRecursively(File file)