Here you can find the source of delete(File file)
Parameter | Description |
---|---|
file | the File to delete. |
true
if the operation was successful; false
otherwise (which includes a null input).
public static boolean delete(File file)
//package com.java2s; /* The contents of this file are subject to the license and copyright terms * detailed in the license directory at the root of the source tree (also * available online at http://fedora-commons.org/license/). *//*from ww w .j av a 2s. c o m*/ import java.io.File; public class Main { /** * Delete a File. * * @param file * the File to delete. * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean delete(File file) { boolean result = true; if (file == null) { return false; } if (file.exists()) { if (file.isDirectory()) { // 1. delete content of directory: File[] children = file.listFiles(); for (File child : children) { //for each file: result = result && delete(child); } //next file } result = result && file.delete(); } //else: input directory does not exist or is not a directory return result; } /** * Delete the specified file or directory. * * @param file * File or directory to delete * @return <code>true</code> if the operation was successful; * <code>false</code> otherwise (which includes a null input). */ public static boolean delete(String file) { return delete(new File(file)); } }