Here you can find the source of delete(File aFile)
public static boolean delete(File aFile)
//package com.java2s; /******************************************************************************* * Copyright (c) 2001, 2007 IBM Corporation 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:// w ww . ja va 2s . co m * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.File; public class Main { /** * deletes a file from the file system; for directories, recurse the subdirectories and delete * them as well * * @return true if successful; false if any file or sub file could not be deleted */ public static boolean delete(File aFile) { if (aFile == null) return true; if (aFile.isDirectory()) { File[] files = aFile.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (!delete(files[i])) return false; } } } return aFile.delete(); } }