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

booleandelete(File f, boolean recursive)
delete
if (!f.exists())
    return false;
if (recursive && f.isDirectory()) {
    File[] children = f.listFiles();
    for (File c : children) {
        if (!delete(c, true))
            return false; 
return f.delete();
booleandelete(File file)
Deletes the given file or directory.
if (!file.exists())
    throw new IOException(file.getName() + " does not exist");
if (isSymlink(file)) {
    return true;
boolean result = true;
if (file.isDirectory()) {
    File[] children = file.listFiles();
...
voiddelete(File file)
delete
if (!isFS2File(file))
    return;
if (file.isDirectory())
    for (File child : file.listFiles())
        delete(child);
file.delete();
booleandelete(File file)
Deletes a file or directory recursively.
if (file.isDirectory()) {
    File[] files = file.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (!delete(files[i]))
            return false;
if (!file.delete()) {
...
intdelete(File file)
delete
if (file == null) {
    return 0;
int deleted = 0;
if (file.isDirectory()) {
    for (File child : file.listFiles()) {
        deleted += delete(child);
if (file.delete()) {
    return deleted + 1;
file.deleteOnExit();
return deleted;
booleandelete(File file)
Delete a file or directory and insure that the file is no longer present on file system.
if (!file.exists()) {
    return true;
if (file.isDirectory()) {
    flushDirectoryContent(file);
file.delete();
if (isFileDeleted(file)) {
...
booleandelete(File file)
Recursively deletes a file or directory and its contents; returns false if something went wrong in the process (which may leave the job partially complete).
if (file == null)
    return true;
if (!file.isDirectory())
    return file.delete();
File[] flist = file.listFiles();
if (flist != null) {
    boolean r = true;
    for (File f : flist) {
...
voiddelete(File file)
Delete the specified file, recursively as necessary.
if (file.exists()) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            delete(files[i]);
    file.delete();
...
voiddelete(File file)
Do File.delete(), ignoring failure.
if (file.exists() && !file.delete()) {
    return;
booleandelete(File file)
Delete the given file (can be a simple file or a folder).
if (file == null)
    return false;
boolean success = true;
if (file.isDirectory()) {
    String[] children = file.list();
    for (int i = 0; i < children.length; i++) {
        success &= delete(new File(file, children[i]));
return (success &= file.delete());