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

booleandeleteFile(String path, String filename)
delete File
File dir = new File(path);
if (!dir.exists())
    throw new FileNotFoundException("Directory " + path + " doesn't exist.");
File serverFile = new File(dir.getAbsolutePath() + File.separator + filename);
boolean result = serverFile.delete();
return result;
voiddeleteFile(String strFolderPath, String strFileName)
Delete a file
File file = new File(strFolderPath + strFileName);
if (file.exists()) {
    if (!file.delete()) {
        throw new IOException("ERROR when deleting the file or folder " + strFolderPath + strFileName);
booleandeleteFile(String strPath)
delete File
boolean bOk = true;
if (strPath == null)
    return false;
File flItem = new File(strPath);
if (flItem != null)
    flItem.delete();
else
    bOk = false;
...
booleandeleteFile(String strPath, String fileName)
delete File
File file = findIt(strPath, fileName);
if (file != null) {
    return file.delete();
return false;
voidDeleteFileFolder(String path)
Delete File Folder
File file = new File(path);
if (file.exists()) {
    do {
        delete(file);
    } while (file.exists());
} else {
    System.out.println("File or Folder not found : " + path);
voiddeleteFileFromDisk(String name, String path)
delete File From Disk
java.io.File file = new java.io.File(path + name);
if (file.isFile() && file.exists()) {
    file.delete();
booleandeleteFileIfExists(String path)
delete File If Exists
File f = new File(path);
if (f.exists() && !f.isDirectory()) {
    return f.delete();
return false;
voiddeleteFileOrDirectory(String path)
delete File Or Directory
deleteFileOrDirectory(new File(path));
voiddeleteFileOrDirectory(String path)
delete File Or Directory
synchronized (path.intern()) {
    File f = new File(path);
    deleteFileOrDirectory(f);
voiddeleteFiles(final File pathname)
Description goes here.
if (pathname.isDirectory()) {
    for (File file : pathname.listFiles()) {
        if (file.isFile()) {
            file.delete();
        } else if (file.isDirectory() && !".".equals(file.getName()) && !"..".equals(file.getName())) {
            deleteFiles(file);
    pathname.delete();