Java Delete File or Directory deleteFileOrDir(File file)

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

Description

Utility method used to delete the profile directory when run as a stand-alone application.

License

Apache License

Parameter

Parameter Description
file The file to recursively delete.

Exception

Parameter Description
IOException is thrown in case of IO issues.

Declaration

public static void deleteFileOrDir(File file) 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   www .j  av  a  2  s .  c  o  m
     * Utility method used to delete the profile directory when run as a
     * stand-alone application.
     * 
     * @param file
     *            The file to recursively delete.
     * @throws IOException
     *             is thrown in case of IO issues.
     **/
    public static void deleteFileOrDir(File file) throws IOException {
        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                deleteFileOrDir(child);
            }
        }
        if (!file.delete()) {
            throw new IOException("Could not remove '" + file + "'!");
        }
    }
}

Related

  1. deleteFileOrDir(File dir, int max)
  2. deleteFileOrDir(File fd)
  3. deleteFileOrDir(File file)
  4. deleteFileOrDir(File filehandle)
  5. deleteFileOrDir(File instanceFileOrDir)
  6. deleteFileOrDirectory(File dir)