Java Delete Directory deleteDirectory(File f)

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

Description

Recursive delete method for deleting directories.

License

Open Source License

Parameter

Parameter Description
f The directory to delete.

Exception

Parameter Description
IOException If the file does not exist.

Declaration

public static void deleteDirectory(File f) throws IOException 

Method Source Code

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

import java.io.File;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    /**/*from  ww  w . j a  va2s  .  c o  m*/
     * Recursive delete method for deleting directories.
     * 
     * @param f The directory to delete.
     * @throws IOException If the file does not exist.
     */
    public static void deleteDirectory(File f) throws IOException {

        // if directory, delete all files in directory
        if (f.isDirectory()) {

            // delete files
            for (File c : f.listFiles())
                deleteDirectory(c);
        }

        // delete file
        if (!f.delete()) {
            throw new FileNotFoundException("Failed to delete file: " + f);
        }
    }
}

Related

  1. deleteDirectory(File directory)
  2. deleteDirectory(File directory)
  3. deleteDirectory(File directory)
  4. deleteDirectory(File directory, boolean ignoreErrors)
  5. deleteDirectory(File f)
  6. deleteDirectory(File f)
  7. deleteDirectory(File f)
  8. deleteDirectory(File file)
  9. deleteDirectory(File file)