Java Utililty Methods File Delete nio

List of utility methods to do File Delete nio

Description

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

Method

booleandeleteIfEmpty(final File directory)
delete If Empty
if (directory.list().length > 0)
    return false;
Files.delete(directory.toPath());
return true;
voiddeleteLocalFile(final String fileName)
delete Local File
Files.deleteIfExists(Paths.get(DOWNLOAD_BASE_NAME + fileName));
voiddeleteLocalFileOrDirectory(File file)
Delete a local file or directory.
if (file.isFile()) {
    Files.delete(file.toPath());
} else if (file.isDirectory()) {
    deleteLocalDirectory(file);
voiddeleteMatching(File baseFile, String regex)
Destroys all files that match the given regex that are in the given directory.
if (baseFile.exists() && baseFile.isDirectory()) {
    for (File child : listFiles(baseFile)) {
        if (child.getName().matches(regex)) {
            try {
                delete(child);
            } catch (IOException ignore) {
booleandeletePidFile()
delete Pid File
Path file = Paths.get(System.getProperty("java.io.tmpdir"), NEO4J_ETL_UI_PID_FILE_NAME);
return file.toFile().delete();
voiddeleteQuietly(File file)
delete Quietly
try {
    Files.deleteIfExists(file.toPath());
} catch (Exception e) {
booleandeleteRecursive(File fileOrDirectory)
Remove specified file or directory.
if (fileOrDirectory.isDirectory()) {
    File[] list = fileOrDirectory.listFiles();
    if (list == null) {
        return false;
    for (File f : list) {
        if (!deleteRecursive(f)) {
            return false;
...
voiddeleteRecursively(File fileOrDir)
delete Recursively
if (fileOrDir.isDirectory() && !Files.isSymbolicLink(fileOrDir.toPath()))
    for (File f : fileOrDir.listFiles())
        deleteRecursively(f);
fileOrDir.delete();
booleandeleteRecursively(File root)
delete Recursively
if (root == null) {
    return false;
try {
    return deleteRecursively(root.toPath());
} catch (IOException ex) {
    return false;
voiddeleteTestFile(String extension)
delete Test File
deleteFile(Paths.get("./test" + extension).toString());