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
try {
    if (file.isDirectory()) {
        for (File subFile : file.listFiles()) {
            delete(subFile);
    if (file.exists())
        file.delete();
...
voiddelete(File file)
Deletes a file or a recursively deletes a directory.
if (file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null) {
        for (File f : files)
            delete(f);
if (!file.delete())
...
voiddelete(File file)
Delete a file or folder including contained files or folders.
if (file.isFile()) {
    file.delete();
} else if (file.isDirectory()) {
    File[] contained = file.listFiles();
    for (int f = 0; f < contained.length; f++) {
        delete(contained[f]);
    file.delete();
...
voiddelete(File file)
Delete a file and raise an exception if unsuccessful.
if (file != null) {
    if (!file.delete()) {
        throw new IOException("Failed to delete file");
voiddelete(File file)

Recursively deletes given file or folder.

if (file.isDirectory()) {
    final File[] children = file.listFiles();
    if (children != null) {
        for (File member : children) {
            delete(member);
file.delete();
voiddelete(File file)
Deletes the given File or directory recursively.
if (file.isDirectory()) {
    String[] files = file.list();
    if (files.length == 0)
        file.delete();
    else {
        for (String temp : files)
            delete(new File(file, temp));
        if (file.list().length == 0)
...
voiddelete(File file)
delete
if (file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null) {
        for (File each : files) {
            delete(each);
for (int i = 0; i < 10; i++) {
    if (file.delete() || !file.exists())
        return;
    try {
        Thread.sleep(10);
    } catch (InterruptedException ignore) {
if (file.exists())
    throw new IOException("Cannot delete file " + file);
voiddelete(File file)
Recursively delete a file or directory.
if (file.exists() && file.isDirectory()) {
    for (File child : listFiles(file)) {
        delete(child);
if (file.exists() && !file.delete()) {
    throw new IOException("Could not delete " + file);
voiddelete(File file)
delete
if (file != null) {
    if (file.isDirectory()) {
        deleteFiles(file);
    file.delete();
booleandelete(File file)
Delete a file ignoring exceptions.
if (file == null) {
    return false;
try {
    return file.delete();
} catch (Exception e) {
    e.printStackTrace();
    return false;
...