Java Utililty Methods Path Delete nio

List of utility methods to do Path Delete nio

Description

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

Method

voidrecursiveDelete(Path pathToBeDeleted)
recursive Delete
Files.walk(pathToBeDeleted).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
voidrecursiveDeleteDirectory(Path dir)
recursive Delete Directory
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        if (LOG_DELETES)
            System.out.println("Deleting FILE " + file);
        if (REALLY_DELETE)
            Files.delete(file);
        return FileVisitResult.CONTINUE;
...
voidrecursiveDeleteOnShutdownHook(final Path path)
recursive Delete On Shutdown Hook
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    @Override
    public void run() {
        try {
            Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file,
                        @SuppressWarnings("unused") BasicFileAttributes attrs) throws IOException {
...
booleanrecursivelyDeleteFilesFromDir(Path aDirectory)
recursively Delete Files From Dir
return !Files.exists(Files.walkFileTree(aDirectory, new SimpleFileVisitor<Path>() {
    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        try {
            Files.delete(file);
        } catch (IOException ioex) {
        return FileVisitResult.CONTINUE;
...
voidrecusiveDeleteIfExists(Path p)
recusive Delete If Exists
if (Files.isDirectory(p)) {
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(p)) {
        for (Path path : directoryStream) {
            recusiveDeleteIfExists(path);
Files.deleteIfExists(p);
...