Java File Delete delete(File f)

Here you can find the source of delete(File f)

Description

delete a file recursivly;

License

Open Source License

Parameter

Parameter Description
f a parameter

Declaration

public static boolean delete(File f) 

Method Source Code


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

public class Main {
    /**//from  w ww  .j av  a 2  s . c om
     * delete a file recursivly;
     *
     * @param path
     */
    public static boolean delete(String path) {
        return delete(new File(path));
    }

    /**
     * delete a file recursivly;
     *
     * @param f
     */
    public static boolean delete(File f) {
        boolean deleted = false;
        if (f.exists()) {
            if (f.isFile()) {
                deleted = f.delete();
            } else {
                File[] subs = f.listFiles();
                if (subs != null && subs.length > 0) {
                    for (int i = 0; i < subs.length; i++) {
                        delete(subs[i]);
                    }
                }
                deleted = f.delete();
            }
        }
        return deleted;
    }
}

Related

  1. delete(File f)
  2. delete(File f)
  3. delete(File f)
  4. delete(File f)
  5. delete(File f)
  6. delete(File f, boolean recursive)
  7. delete(File file)
  8. delete(File file)
  9. delete(File file)