Here you can find the source of deleteRecursive(File file)
public static void deleteRecursive(File file) throws IOException
//package com.java2s; /**//from w w w . ja v a2 s . c om * Copyright (c) 2013 Puppet Labs, Inc. and other contributors, as listed below. * 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 * * Contributors: * Puppet Labs */ import java.io.File; import java.io.IOException; import java.util.HashSet; import java.util.Set; public class Main { public static void deleteRecursive(File file) throws IOException { Set<File> visited = new HashSet<File>(); deleteRecursive(file, visited); } private static void deleteRecursive(File file, Set<File> visited) throws IOException { if (visited.contains(file)) throw new IOException("Circular file structure detected"); visited.add(file); if (file.isDirectory()) { for (File subFile : file.listFiles()) deleteRecursive(subFile, visited); } if (!file.delete()) { if (file.exists()) throw new IOException("Unable to delete " + file.getAbsolutePath()); } } public static void deleteRecursive(String path) throws IOException { deleteRecursive(new File(path)); } }