Here you can find the source of deleteDirectory(File dir)
public static void deleteDirectory(File dir) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2014,2015 Hideki Yatomi * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ import java.io.*; import java.nio.file.*; public class Main { public static void deleteDirectory(File dir) throws IOException { if (dir.exists() && dir.isDirectory()) { for (File child : dir.listFiles()) { if (child.isDirectory()) { deleteDirectory(child); } else { Files.delete(child.toPath()); }/*w ww . j a v a2s . c o m*/ } Files.delete(dir.toPath()); } } public static void delete(File file) throws IOException { Files.delete(file.toPath()); } }