Java Utililty Methods File Delete

List of utility methods to do File Delete

Description

The list of methods to do File Delete are organized into topic(s).

Method

voiddelete(File file)
Delete a file.
if (file == null || !file.exists())
    return;
if (!file.delete())
    throw new IOException("Unable to delete file " + file.getAbsolutePath());
booleandelete(File file)
delete
if (file == null || !file.exists()) {
    return false;
boolean result = true;
if (file.isDirectory()) {
    String[] children = file.list();
    for (int i = 0; i < children.length; i++) {
        result &= delete(new File(file, children[i]));
...
voiddelete(File file)
delete
if (file.isDirectory() && file.list().length > 0) {
    String files[] = file.list();
    for (String tmpFile : files) {
        File fileToDelete = new File(file, tmpFile);
        delete(fileToDelete);
file.delete();
...
voiddelete(File file)
same as file.delete() if 'file' is file; recursively deletes all elements inside if 'file' is directory.
if (file.isFile()) {
    file.delete();
} else {
    for (File f : file.listFiles()) {
        delete(f);
    file.delete();
voiddelete(File file)
Deletes the specified file, throwing a RuntimeException if the delete fails.
if (!file.delete()) {
    throw new RuntimeException("File " + file.getAbsolutePath() + " can't be deleted.");
booleandelete(File file)
Delete a File.
boolean result = true;
if (file == null) {
    return false;
if (file.exists()) {
    if (file.isDirectory()) {
        File[] children = file.listFiles();
        for (File child : children) { 
...
voiddelete(File file)
delete
if (file.isDirectory()) {
    File[] children = file.listFiles();
    for (int i = 0; i < children.length; i++) {
        delete(children[i]);
if (!file.delete()) {
    throw new IOException("Unable to delete " + file.getPath());
...
booleandelete(File file)
Deletes recursively the given file (if it is a directory) or just removes itself
if (file.isDirectory()) {
    File[] contents = file.listFiles();
    if (null != contents) {
        for (File child : contents) {
            delete(child);
    file.delete();
...
voiddelete(File file)
delete
if (file.isDirectory()) {
    if (file.list().length == 0) {
        file.delete();
        System.out.println("Directory is deleted : " + file.getAbsolutePath());
    } else {
        String files[] = file.list();
        for (String temp : files) {
            File fileDelete = new File(file, temp);
...
booleandelete(File file)
Delete a file or directory and insure that the file is no longer present on file system.
if (file.isDirectory()) {
    flushDirectoryContent(file);
file.delete();
if (isFileDeleted(file)) {
    return true;
return waitUntilFileDeleted(file);
...