Here you can find the source of deleteDirectoryAndContents(String dir)
public static void deleteDirectoryAndContents(String dir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.*; public class Main { public static void deleteDirectoryAndContents(String dir) throws IOException { deleteDirectoryAndContents(Paths.get(dir)); }/* w ww.java 2 s . com*/ public static void deleteDirectoryAndContents(Path dir) throws IOException { cleanDirectory(dir); Files.delete(dir); } public static void cleanDirectory(String dir) throws IOException, InvalidPathException { cleanDirectory(Paths.get(dir)); } public static void cleanDirectory(Path dir) throws IOException { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path file : stream) { if (Files.isDirectory(file)) { cleanDirectory(file); } Files.delete(file); } } catch (DirectoryIteratorException x) { throw new IOException(x); } } }