Java File Path Delete deleteDir(File path)

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

Description

Recursively delete a directory and all the files it contains.

License

Apache License

Parameter

Parameter Description
path path to delete

Exception

Parameter Description
IOException if the delete fails

Declaration

public static void deleteDir(File path) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//from  ww  w  .  ja v a2s  .  c  o m
     * Recursively delete a directory and all the files it contains.
     * 
     * @param path path to delete
     * @throws IOException if the delete fails
     */
    public static void deleteDir(File path) throws IOException {
        try {

            if (path.isDirectory()) {
                File[] files = path.listFiles();
                if (files != null) {
                    for (int i = 0; i < files.length; i++) {
                        deleteDir(files[i]);
                    }
                }
            }
            path.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. deleteDir(File f)
  2. deleteDir(File f)
  3. deleteDir(File fDir)
  4. deleteDir(File file)
  5. deleteDir(File path)
  6. deleteDir(File path)
  7. deleteDir(File path)
  8. deleteDir(final String path)
  9. deleteDir(String path)