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

voiddeleteIfExist(String filePath)
Delete the file/directory if exist.
File file = new File(filePath);
if (file.exists()) {
    file.delete();
voiddeleteInPathTempFiles(String workingFolder)
delete In Path Temp Files
String destFolder = workingFolder + "/OPS000";
for (Object[] xmlGraph : getProviderGraphs()) {
    String resourceFile = xmlGraph[0].toString();
    new File(destFolder.concat(resourceFile)).delete();
new File(destFolder.concat(destFolder)).delete();
voiddeleteInRemote(String host, String path)
delete In Remote
if (!runCommandInRemoteHost(host, "rm -rf " + path, 0).isEmpty())
    throw new IOException("fail to delete " + path + " in " + host);
voiddeleteJaasFile(String jaasPath)
delete Jaas File
File jaasFile = new File(jaasPath);
if (jaasFile.exists()) {
    if (!jaasFile.delete()) {
        throw new IOException("Failed to delete exists jaas file.");
voiddeleteKey(String path, String key)
Deletes a registry key from the Windows registry.
Objects.requireNonNull(path);
List<String> command = new ArrayList<>();
command.add("reg");
command.add("delete");
command.add(path);
if (key != null) {
    command.add("/v");
    command.add(key);
...
voiddeleteMultipleFiles(String filePath, int numberOfFiles)
delete Multiple Files
for (int i = 0; i < numberOfFiles; i++) {
    deleteRecursively(new File(filePath + "." + (i + 1)));
booleandeleteNonEmptyDirectory(String dirPath)
Deletes a non-empty directory, defined by dirPath from the file system.
File dir = new File(dirPath);
if (dir.exists() && dir.isDirectory()) {
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        boolean fileDeleted = file.delete();
        if (!fileDeleted)
            return false;
...
voiddeleteOldStorageFile(String filepath)
Delete the original storage file that the activity manager is saved in
File oldStorage = new File(filepath);
oldStorage.delete();
voiddeleteParent(String filePath)
Delete source file and parent folder if empty
File file = new File(filePath);
if (file.exists()) {
    file.delete();
File parent = file.getParentFile();
while (parent.exists() && parent.isDirectory() && parent.listFiles().length == 0) {
    parent.delete();
    parent = parent.getParentFile();
...
voiddeletePath(File dirPath)

Utilities for Files.

recursiveDelete(dirPath);
dirPath.delete();