-
Notifications
You must be signed in to change notification settings - Fork 0
Java snippets
Nimrod edited this page Dec 1, 2019
·
1 revision
-
Removes a directory and all of its subdirectories and their files.
/**
-
Removes a directory and all of its subdirectories and their files.
-
@param path The path of an existing directory. Returns siletly if the path does not exist.
-
@throws IOException If failed to traverse tree (due to permissions, hardware failure, etc.) */ static void removeDir(Path path) throws IOException { if (!path.toFile().exists()) { return; } Files.walkFileTree(path, new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; }
@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; }
});
-
-
Refer to subclass in base class
class A<T extends A> { T foo(); } class B extends A { @Override B foo(); }