Java File Delete delete(File file)

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

Description

Recursively deletes file or directory.

License

Open Source License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void delete(File file) throws IOException 

Method Source Code


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

import java.io.File;
import java.io.IOException;

public class Main {
    /**/*from  w  w w.j  a  v a  2 s  .  c  om*/
     * Recursively deletes file or directory.
     * @param file
     * @throws IOException
     */
    public static void delete(File file) throws IOException {
        if (file.exists()) {
            if (file.isDirectory()) {
                for (File c : file.listFiles()) {
                    delete(c);
                }
            }
            if (!file.delete()) {
                throw new IOException("Could not delete " + file.getAbsolutePath());
            }
        }
    }
}

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)