Here you can find the source of deleteDir(final String path)
public static void deleteDir(final String path) throws IOException
//package com.java2s; /**/* w w w . j a va2s . c om*/ * Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved. * EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * http://www.ewcms.com */ import java.io.File; import java.io.IOException; public class Main { public static void deleteDir(final String path) throws IOException { File file = new File(path); deleteDir(file); } public static void deleteDir(File dir) throws IOException { if (dir.isFile()) { throw new IOException("IOException -> BadInputException: not a directory."); } File[] files = dir.listFiles(); if (files == null) { dir.delete(); return; } for (File file : files) { if (file.isFile()) { file.delete(); } else { deleteDir(file); } } } public static void delete(final String path) throws IOException { File file = new File(path); delete(file); } public static void delete(final File file) throws IOException { if (!file.exists()) { return; } if (file.isFile()) { deleteFile(file); } else { deleteDir(file); } } public static void deleteFile(final String path) throws IOException { File file = new File(path); deleteFile(file); } public static void deleteFile(File file) throws IOException { if (file.isDirectory()) { throw new IOException("IOException -> BadInputException: not a file."); } if (file.exists() == false) { return; } if (file.delete() == false) { throw new IOException("Cannot delete file. filename = " + file.getPath()); } } }