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
if (null == file)
    throw new IllegalArgumentException("Illegal 'file' argument in Utils.delete(File): " + file);
if (file.exists()) {
    if (file.isDirectory()) {
        for (File child : file.listFiles()) {
            delete(child);
    file.delete();
voiddelete(File file)
delete
if (file.isDirectory()) {
    deleteChildren(file);
deleteFile(file);
voiddelete(File file)
Will recursively delete a directory
if (file == null) {
    return;
if (file.isDirectory()) {
    String files[] = file.list();
    if (files != null) {
        if (files.length != 0) {
            for (String temp : files) {
...
voiddelete(File file)
delete
if (!file.exists())
    return;
if (file.isDirectory()) {
    if (file.list().length == 0) {
        file.delete();
    } else {
        String files[] = file.list();
        for (String temp : files) {
...
voiddelete(File file)
delete
if (file.isDirectory()) {
    File[] files = file.listFiles();
    for (File file2 : files)
        delete(file2);
if (!file.delete())
    throw new RuntimeException("Failed to delete file: " + file);
booleandelete(File file)
Delete a file or directory.
if (file.isDirectory()) {
    File[] entries = file.listFiles();
    if (entries != null) {
        for (File entry : entries) {
            if (!delete(entry)) {
                return false;
return file.delete();
voiddelete(File file)
delete
if (file != null && file.exists()) {
    boolean deleted = file.delete();
    if (!deleted) {
        file.deleteOnExit();
voiddelete(File file)
delete
if (writeable(file)) {
    if (file.isDirectory()) {
        for (File f : file.listFiles())
            delete(f);
    file.delete();
voiddelete(File file)
delete
try {
    file.delete();
} catch (Exception e) {
    throw new Exception(file.toString() + ": Can't delete");
booleandelete(File file)
deletes files and directories
if (file != null && file.exists()) {
    if (file.isDirectory()) {
        for (File child : file.listFiles()) {
            delete(child);
    return file.delete();
} else {
...