Here you can find the source of deleteFiles(File directory)
private static void deleteFiles(File directory)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 SAP and others./*from w w w . ja va 2 s .com*/ * 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: * SAP - initial API and implementation *******************************************************************************/ import java.io.File; public class Main { private static void deleteFiles(File directory) { if (directory != null) { for (File file : directory.listFiles()) { if (file.isDirectory()) { deleteDirectory(file); } if (!file.delete()) { file.deleteOnExit(); } } } } public static void deleteDirectory(File directory) { if (directory != null) { deleteFiles(directory); directory.delete(); } } }