Java Path Delete nio doDelete(@Nonnull Path path)

Here you can find the source of doDelete(@Nonnull Path path)

Description

do Delete

License

Open Source License

Declaration

private static void doDelete(@Nonnull Path path) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

import static java.nio.file.FileVisitResult.CONTINUE;
import static java.nio.file.Files.*;

public class Main {
    private static void doDelete(@Nonnull Path path) throws IOException {
        final FileStore fileStore = Files.getFileStore(path);
        if (fileStore.supportsFileAttributeView("dos")) {
            setAttribute(path, "dos:readonly", false);
            setAttribute(path, "dos:system", false);
            setAttribute(path, "dos:hidden", false);
        }/*from   w w w.j a  v a2 s .c  o m*/
        Files.delete(path);

    }

    public static void delete(@Nullable Path path) throws IOException {
        if (path == null || !exists(path)) {
            return;
        }
        if (isRegularFile(path)) {
            doDelete(path);
            return;
        }
        walkFileTree(path, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                doDelete(file);
                return CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                doDelete(dir);
                return CONTINUE;
            }
        });
    }
}

Related

  1. deleteRecursively(final Path path)
  2. deleteRecursively(Path directory)
  3. deleteRecursively(Path path)
  4. deleteTmpDir(Path path)
  5. deleteTreeBelowPath(Path startHerePath)
  6. forceDelete(Path path)
  7. optimisticDelete(Path path)
  8. readAndDelete(final Path p)
  9. recursiveDelete(Path directory)