Java Utililty Methods File Path Delete

List of utility methods to do File Path Delete

Description

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

Method

voiddeleteFile(String path)
Delete file
deleteFile(new File(path));
voiddeleteFile(String path)
Recursive deletion engine, traverses through all sub-directories, attempting to delete every file and directory it comes across.
if (path == null)
    throw new IOException("Input file path is null");
deleteFile(new File(path));
voiddeleteFile(String path)
delete File
File file = new File(path);
if (!file.exists()) {
    return;
if (!file.isDirectory()) {
    if (file.isFile()) {
        file.delete();
    return;
String[] tempList = file.list();
String childFilePath = null;
for (int i = 0; i < tempList.length; i++) {
    if (path.endsWith(File.separator)) {
        childFilePath = path + tempList[i];
    } else {
        childFilePath = path + File.separator + tempList[i];
    File temp = new File(childFilePath);
    if (temp.isFile()) {
        temp.delete();
    } else if (temp.isDirectory()) {
        deleteFile(childFilePath);
file.delete();
booleandeleteFile(String path)
Delete file according to a path.
File file = new File(path);
return deleteFile(file);
voiddeleteFile(String path)
delete File
try {
    File file = new File(path);
    if (file.delete()) {
        System.out.println(file.getName() + " is deleted!");
    } else {
        System.out.println("Delete operation is failed.");
} catch (Exception e) {
...
voiddeleteFile(String path)
delete file
File file = new File(path);
file.deleteOnExit();
voiddeleteFile(String path)
Utility method to delete a file from one location
File f = null;
f = new File(path);
if (f.exists()) {
    f.delete();
intdeleteFile(String path)
deleteFile
int res = 0;
File temp = new File(path);
if (temp.exists() && temp.delete()) {
    res = 1;
return res;
voiddeleteFile(String path)
Convenience function to delete a file.
if (!new File(path).delete())
    throw new IOException(String.format("Unable to delete file '%s'", path));
booleandeleteFile(String path)
Delete file.
File file = new File(path);
if (file.isDirectory()) {
    for (File subfile : file.listFiles()) {
        deleteFile(subfile.getAbsolutePath());
file.delete();
return true;
...