Java Delete File deleteFile(final File file)

Here you can find the source of deleteFile(final File file)

Description

delete file or directory

License

Open Source License

Parameter

Parameter Description
file file path

Return

true - if the file/directory has been deleted
false otherwise

Declaration

public static boolean deleteFile(final File file) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    /**//from  w  ww  .  jav  a  2 s  . c  o  m
     * delete file or directory
     * 
     * @param file
     *            file path
     * @return true - if the file/directory has been deleted<br>
     *         false otherwise
     */
    public static boolean deleteFile(final File file) {
        // delete directory content recursively
        if (file.isDirectory()) {
            final File[] children = file.listFiles();
            for (File child : children) {
                if (!deleteFile(child)) {
                    return false;
                }
            }
        }

        // delete file/empty directory
        return file.delete();
    }
}

Related

  1. deleteFile(File file)
  2. deleteFile(File file)
  3. deleteFile(File source)
  4. deleteFile(final File f, final int attempts, final long sleepTime)
  5. deleteFile(final File file)
  6. deleteFile(final File file)
  7. deleteFile(final File file)
  8. deleteFile(final String dirname)
  9. deleteFile(Object fileObj)