Skip to content

Instantly share code, notes, and snippets.

@thekalinga
Created August 28, 2019 13:03
Show Gist options
  • Save thekalinga/079b0ef4c5b6665fcf710eab0b5c61c4 to your computer and use it in GitHub Desktop.
Save thekalinga/079b0ef4c5b6665fcf710eab0b5c61c4 to your computer and use it in GitHub Desktop.
Delete directory recursively in java8
public static void deleteDirRecursively(Path pathToDel) throws IOException {
Files.walk(pathToDel)
.sorted(reverseOrder()) // dir would be listed before the files inside. So, we delete the files in the right order
.forEach(path -> run(() -> delete(path)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment