Here you can find the source of cleanDir(final File dir, final String exclude)
public static void cleanDir(final File dir, final String exclude)
//package com.java2s; /*=============================================================================# # Copyright (c) 2009-2015 Stephan Wahlbrink (WalWare.de) and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the GNU Lesser General Public License # v2.1 or newer, which accompanies this distribution, and is available at # http://www.gnu.org/licenses/lgpl.html # /*from ww w.ja v a 2 s. c o m*/ # Contributors: # Stephan Wahlbrink - initial API and implementation #=============================================================================*/ import java.io.File; public class Main { public static void cleanDir(final File dir, final String exclude) { final String[] children = dir.list(); for (final String child : children) { if (child.equals(exclude)) { continue; } final File file = new File(dir, child); if (file.isDirectory()) { delDir(file); } else { file.delete(); } } } public static boolean delDir(final File dir) { final String[] children = dir.list(); for (final String child : children) { final File file = new File(dir, child); if (file.isDirectory()) { delDir(file); } else { file.delete(); } } return dir.delete(); } }