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

booleandeleteFile(String f)
delete File
boolean success = false;
File fTarget = new File(f);
if (fTarget.exists()) {
    success = fTarget.delete();
return success;
voiddeleteFile(String file)
delete File
File f = new File(file);
if (f.exists())
    f.delete();
voiddeleteFile(String file)
delete File
File f = new File(file);
if (f.exists() && !f.delete()) {
    throw new IllegalStateException("Deletion failed " + file);
voiddeleteFile(String file)
Delete a file.
File f = new File(file);
boolean retVal = f.delete();
if (!retVal) {
    System.err.println(String.format("Error - could not delete %s", file));
booleandeleteFile(String file)
Delete a file
File f = new File(file);
if (f.exists() && f.isFile()) {
    return f.delete();
return true;
voiddeleteFile(String filename)
Utility method to delete a file if it exists.
File file = new File(filename);
if (file.exists()) {
    if (!file.delete()) {
        throw new Exception("Could not delete file " + file);
booleandeleteFile(String fileName)
delete a file from the system, if exists
File file = new File(fileName);
if (!file.exists() || file.isDirectory()) {
    return false;
file.delete();
return true;
booleandeleteFile(String fileName)
delete File
File file = new File(fileName);
if (file.exists() && file.isFile()) {
    return file.delete();
return false;
voiddeleteFile(String fileName)
delete File
File f = new File(fileName);
if (f.exists()) {
    f.delete();
    if (f.exists())
        f.deleteOnExit();
voiddeleteFile(String filename)
Delete file.
try {
    File f1 = new File(filename);
    boolean success = f1.delete();
    if (!success) {
    } else {
} catch (Exception e) {