Here you can find the source of deleteNotEmptyDirectory(Path path)
public static void deleteNotEmptyDirectory(Path path) throws IOException
//package com.java2s; //License from project: Apache License import static java.nio.file.FileVisitResult.CONTINUE; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; public class Main { public static void deleteNotEmptyDirectory(Path path) throws IOException { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override//from w w w. j av a 2s . c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc == null) { Files.delete(dir); return CONTINUE; } else { throw exc; } } }); } }