Java Utililty Methods Delete File

List of utility methods to do Delete File

Description

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

Method

voiddeleteFile(File source)
delete File
if (source.exists()) {
    source.delete();
booleandeleteFile(final File f, final int attempts, final long sleepTime)
delete File
int retries = attempts;
while (retries > 0) {
    if (f.delete()) {
        break;
    retries--;
    try {
        Thread.sleep(sleepTime);
...
booleandeleteFile(final File file)
delete file or directory
if (file.isDirectory()) {
    final File[] children = file.listFiles();
    for (File child : children) {
        if (!deleteFile(child)) {
            return false;
return file.delete();
voiddeleteFile(final File file)
Opens a thread to delete the specified file.
new Thread(new Runnable() {
    @Override
    public void run() {
        while (file.exists()) {
            file.delete();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
...
booleandeleteFile(final File file)
Deletes the specified file.
try {
    return file.delete();
} catch (final Exception ex) {
    ex.printStackTrace();
    return false;
booleandeleteFile(final File file)
deletes recursevelly a directory
if (file == null) {
    throw new NullPointerException("file");
boolean status = true;
if (file.isDirectory()) {
    for (File child : file.listFiles()) {
        status = status && deleteFile(child);
return status && file.delete();
booleandeleteFile(final String dirname)
delete File
final File f = new File(dirname);
if (f.exists()) {
    return deleteR(f);
return false;
booleandeleteFile(Object fileObj)
Deletes a file from the file system.
if (fileObj instanceof File) {
    return deleteFile((File) fileObj);
return false;
voiddeleteFile(String archiveFilename)
delete File
try {
    new File(archiveFilename).delete();
} catch (Exception ex) {
    throw new RuntimeException("Cannot remove file: " + archiveFilename, ex);
voiddeleteFile(String dest)
delete File
deleteFile(new File(dest));