Here you can find the source of deleteDir(File directory, boolean removeAll)
public static void deleteDir(File directory, boolean removeAll)
//package com.java2s; /****************************************************************************** * Copyright (c) 2010 Oracle/*from w w w . ja v a2 s . c o m*/ * 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 * * Original file was copied from * org.eclipse.wst.common.project.facet.core.util.internal.FileUtil * ******************************************************************************/ import java.io.File; public class Main { public static void deleteDir(File directory, boolean removeAll) { if (directory == null || !directory.isDirectory()) { return; } for (File file : directory.listFiles()) { if (file.isDirectory() && removeAll) { deleteDir(file, removeAll); } else { file.delete(); } } directory.delete(); } }