List of utility methods to do Path Delete nio
void | deleteLockFile(Path logFile) Removes any lck files for the given log file. String lockFileName = logFile.getFileName().toString().concat(".lck"); Path parent = logFile.getParent(); Path lockFile; if (parent == null) { lockFile = Paths.get(lockFileName); } else { lockFile = parent.resolve(lockFileName); Files.deleteIfExists(lockFile); |
void | deleteNotEmptyDirectory(Path path) delete Not Empty Directory Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return CONTINUE; @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { ... |
void | deleteOnExit(Path path) Register Path for a delete on JM shutdown event. DELETE_ON_EXIT_PATHS.add(path); |
void | deletePath(Path path) delete Path if (path == null) { return; File file = path.toFile(); if (file.isDirectory()) { for (File item : file.listFiles()) { deletePath(item.toPath()); deleteFile(file); |
void | deletePathRecursively(String path) Deletes a path recursively. Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; @Override ... |
void | deleteQuietly(@Nullable Path path) delete Quietly if (path == null || !exists(path)) { return; if (isRegularFile(path)) { try { doDelete(path); } catch (final IOException ignored) { return; try { walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { try { doDelete(file); } catch (final IOException ignored) { return CONTINUE; @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) { try { doDelete(dir); } catch (final IOException ignored) { return CONTINUE; }); } catch (final IOException ignored) { |
void | deleteQuietly(Path dir) Deletes the directory recursively and quietly. try { Files.walk(dir).sorted(Comparator.reverseOrder()).forEach(file -> { try { Files.delete(file); } catch (IOException e) { }); } catch (IOException e) { ... |
void | deleteRecursive(Path path) Recursively delete the given path Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { ... |
void | deleteRecursive(Path path) delete Recursive Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { ... |
void | deleteRecursively(final Path path) delete Recursively deleteRecursively(path, true); |