Here you can find the source of delete(File file)
public static boolean delete(File file)
//package com.java2s; /**// ww w.j a v a 2 s . c o m * AC - A source-code copy detector * * For more information please visit: http://github.com/manuel-freire/ac * * **************************************************************************** * * This file is part of AC, version 2.0 * * AC is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the * Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * AC is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with AC. If not, see <http://www.gnu.org/licenses/>. */ import java.io.*; public class Main { /** * Deletes a file or directory recursively. Returns 'true' if ok, or * 'false' on error. */ public static boolean delete(File file) { // Recursive call if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (!delete(files[i])) return false; } } // File deletion if (!file.delete()) { System.err.println("Imposible to delete file " + file.getAbsolutePath()); return false; } return true; } }