Here you can find the source of deleteDirectory(File directory)
public static void deleteDirectory(File directory) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class Main { public static void deleteDirectory(File directory) throws IOException { cleanDirectory(directory);// ww w .j a va 2s.co m Files.delete(Paths.get(directory.getAbsolutePath())); } public static void cleanDirectory(File directory) throws IOException { if (!directory.isDirectory()) { throw new IllegalArgumentException(directory + " is not a directory"); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } for (File file : files) { delete(file); } } public static void delete(File file) throws IOException { if (file.isDirectory()) { deleteDirectory(file); return; } Files.delete(Paths.get(file.getPath())); } }