This question already has an answer here: Delete files recursively in Java 14 ... If you use Apache Commons IO it's a one-liner: FileUtils.deleteDirectory(dir);.
stackoverflow.com