Java File Delete delete(File file)

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

Description

Delete the specified file, recursively as necessary.

License

Open Source License

Parameter

Parameter Description
file The file to delete

Declaration

public static void delete(File file) 

Method Source Code


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

public class Main {
    /**//w w w.j  a  va2  s  . com
     * Delete the specified file, recursively as necessary.
     * 
     * @param file The file to delete
     */
    public static void delete(File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] files = file.listFiles();
                for (int i = 0; i < files.length; i++) {
                    delete(files[i]);
                }
            }
            file.delete();
        }
    }

    /**
     * Delete the specified file, recursively as necessary.
     * 
     * @param fileName The file to delete
     */
    public static void delete(String fileName) {
        delete(new File(fileName));
    }
}

Related

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