Java Delete File Recursively deleteRecursive(File file)

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

Description

Deletes a directory or file <p/> Taken from http://forum.java.sun.com/thread.jspa?threadID=470197&messageID=2169110 <p/> Author: jfbriere

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static void deleteRecursive(File file) 

Method Source Code


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

import java.io.File;

public class Main {
    /**//  w  ww .  j a  va  2  s.  c  o  m
     * Deletes a directory or file
     * <p/>
     * Taken from
     * http://forum.java.sun.com/thread.jspa?threadID=470197&messageID=2169110
     * <p/>
     * Author: jfbriere
     *
     * @param file
     */
    public static void deleteRecursive(File file) {
        if (file.isDirectory()) {
            File[] fileArray = file.listFiles();

            if (fileArray != null) {
                for (File aFileArray : fileArray) {
                    deleteRecursive(aFileArray);
                }
            }
        }
        if (!file.delete()) {
            System.err.println("Cannot delete file");
        }
    }
}

Related

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