Java Delete File Recursively deleteRecursive(File dir)

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

Description

Recursively deletes an entire directory hierarchy.

License

Open Source License

Return

true iff the directory hierarchy was successfully deleted.

Declaration

public static boolean deleteRecursive(File dir) 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/*  w ww  .j av a  2  s  . c om*/
     * Recursively deletes an entire directory hierarchy.
     * @return true iff the directory hierarchy was successfully deleted.
     */
    public static boolean deleteRecursive(File dir) {
        if (!dir.exists())
            return (true);

        boolean success = true;
        String files[] = dir.list();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = new File(dir, files[i]);
                if (file.isDirectory())
                    success &= deleteRecursive(file);
                else
                    success &= file.delete();
            }
        }

        success &= dir.delete();
        return (success);
    }
}

Related

  1. deleteR(File dir)
  2. deleteRec(File f)
  3. deleteRecursive(File dir)
  4. deleteRecursive(File dir)
  5. deleteRecursive(File dir)
  6. deleteRecursive(File dir)
  7. deleteRecursive(File f)
  8. deleteRecursive(File f)