Here you can find the source of delete(File file)
public static int delete(File file)
//package com.java2s; /*//from ww w. j a va2s. c o m * Copyright (c) 2007-2013, 2015 Eike Stepper (Berlin, Germany) and others. * 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: * Eike Stepper - initial API and implementation * Christian W. Damus (CEA LIST) - bug 418454 */ import java.io.File; public class Main { public static int delete(File file) { if (file == null) { return 0; } int deleted = 0; if (file.isDirectory()) { for (File child : file.listFiles()) { deleted += delete(child); } } if (file.delete()) { return deleted + 1; } file.deleteOnExit(); return deleted; } }