Android Directory Delete deleteDirectory(File path)

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

Description

Convenience function to delete a directory.

License

Open Source License

Parameter

Parameter Description
path Path to delete

Exception

Parameter Description
IOException If the operation fails.

Declaration

public static void deleteDirectory(File path) 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 {
    /**//  w  w  w  . ja  va 2s  .  c o  m
     * Convenience function to delete a directory.
     * 
     * @param path Path to delete
     * @throws IOException If the operation fails.
     */
    public static void deleteDirectory(File path) throws IOException {
        if (!path.exists())
            return;

        for (File file : path.listFiles()) {
            if (file.isDirectory())
                deleteDirectory(file);
            else if (!file.delete()) {
                throw new IOException(String.format(
                        "Unable to delete file '%s'", file));
            }
        }

        if (!path.delete())
            throw new IOException(String.format(
                    "Unable to delete directory '%s'", path));
    }
}

Related

  1. deleteDirectory(File dir)
  2. deleteDirectory(File directory)
  3. deleteDirectory(File directory)
  4. deleteDirectory(File path)
  5. deleteDirectory(File path)
  6. deleteDirectory(File path)
  7. deleteDirectory(String directory)
  8. deleteDirectory(String path)
  9. deleteDirectory(String path)