Java Utililty Methods Folder Delete nio

List of utility methods to do Folder Delete nio

Description

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

Method

voiddelete(Path folder, List noDeleteFiles)
delete
delete(folder, folder, noDeleteFiles);
voiddeleteEmptyFolder(String... dirNames)
delete Empty Folder
File dir = generateFileObject(dirNames);
System.out.println("Deleting folder '" + dir + "'");
try {
    Files.delete(dir.toPath());
} catch (IOException e) {
    throw new Exception(
            e.getClass().getSimpleName() + " deleting empty folder '" + dir + "' : " + e.getMessage());
booleandeleteFile(String folderName, String fileName)
delete File
Path filePath = Paths.get(folderName, fileName);
boolean deleted = Files.deleteIfExists(filePath);
return deleted;
voiddeleteFolder(Path folder)
delete Folder
if (folder.toFile().exists() && folder.toFile().isDirectory()) {
    System.out.println("deleting " + folder.toAbsolutePath());
    deleteRecursive(folder.toFile());
voiddeleteFolder(Path path)
Deletes a directory if it exists.
deleteFolder(path, true);
voiddeleteFolderAndSubfolders(Path pathToFile)
Delete folder and all subcontents.
File f = pathToFile.toFile();
File[] currentFileList;
Stack<File> stack = new Stack<>();
stack.push(f);
while (!stack.isEmpty()) {
    if (stack.lastElement().isDirectory()) {
        currentFileList = stack.lastElement().listFiles();
        if (currentFileList.length > 0) {
...
voiddeleteRecursively(File folder)
Recursively deletes a folder and all its content
Files.walkFileTree(folder.toPath(), new SimpleFileVisitor<Path>() {
    @Override
    public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
        if (e == null) {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        } else {
            throw e;
...