List of utility methods to do Path Delete nio
void | recursiveDelete(Path pathToBeDeleted) recursive Delete Files.walk(pathToBeDeleted).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); |
void | recursiveDeleteDirectory(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; ... |
void | recursiveDeleteOnShutdownHook(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 { ... |
boolean | recursivelyDeleteFilesFromDir(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; ... |
void | recusiveDeleteIfExists(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); ... |