List of utility methods to do Path Remove nio
void | appendOrRemove(LinkedList Add path to the stack if path is directory, otherwise delete it. for (Path p : ds) { if (Files.isDirectory(p)) paths.add(p); else Files.delete(p); |
void | recursiveRemoveFolder(Path folderPath) recursive Remove Folder if (!folderPath.startsWith(Paths.get(TMP_DIR))) { throw new IllegalArgumentException("Refuse to delete a folder that is not in the system tmpdir"); Files.walkFileTree(folderPath, new FileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { System.out.println("Deleting directory: " + dir); Files.delete(dir); ... |
void | removeDirectory(Path directory) remove Directory Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { ... |
void | removeDirectory(Path directory) Remove a directory and all of its contents. final Path canonicalPath = directory.toAbsolutePath().normalize(); if (canonicalPath.equals(canonicalPath.getRoot())) throw new IOException("Refusing to delete root directory."); Files.walkFileTree(canonicalPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; ... |
boolean | removeDirectory(String pathToDir) Remove directory and all its sub-resources with specified path return deleteRecursive(new File(pathToDir)); |
void | removeDirectoryIfItIsEmpty(Path directoryToRemove) Checks if directoryToRemove is empty itself and remove it if it is empty only. if (Files.exists(directoryToRemove) && Files.isDirectory(directoryToRemove)
&& Files.list(directoryToRemove).collect(toList()).isEmpty()) {
Files.delete(directoryToRemove);
|
Path | removeDriveLetter(Path path) Remove the root component from the path, returning a relative path. if (path == null) { return null; if (path.isAbsolute()) { return Paths.get(path.getRoot().relativize(path).toString()); } else { return path; |
void | removeFile(final String removePath) remove File try { final Path path = Paths.get(removePath); Files.delete(path); } catch (final IOException e) { System.err.println("Couldn't delete file. Exception: " + e); |
boolean | removeFile(String path) remove File File fileToRemove = loadFile(path);
return fileToRemove.delete();
|
void | removeFile(String workspacePath) remove File Path path = FileSystems.getDefault().getPath(workspacePath); Files.delete(path); |