Java Delete File or Directory deleteFileOrDir(File fd)

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

Description

Deletes the directory or file fd from the file system.

License

Open Source License

Declaration

public static void deleteFileOrDir(File fd) 

Method Source Code


//package com.java2s;

import java.io.File;

public class Main {
    /**/*from  w ww .  ja  va 2  s.com*/
     * Deletes the directory or file <code>fd</code> from the file
     * system. Throws a {@link IllegalStateException} if the specified file
     * system entity cannot be deleted (e.g., because there is an open
     * file handle to that entity, or because the entity is a non-empty
     * directory).
     */
    public static void deleteFileOrDir(File fd) {
        boolean deleted = fd.delete();
        if (!deleted) {
            String type = fd.isFile() ? "file" : "directory";
            throw new IllegalStateException("Unable to delete " + type + " '" + fd.getPath() + "'");
        }
    }
}

Related

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