Here you can find the source of doDeleteFileOrDir(File fileOrDir)
Parameter | Description |
---|---|
fileOrDir | file or directory to be deleted |
true
if specified file or directory has been deleted; false
otherwise
public static boolean doDeleteFileOrDir(File fileOrDir)
//package com.java2s; import java.io.File; public class Main { /**/*w w w . j a v a2 s.com*/ * Deletes specified file or directory. A directory is recursively * deleted. * * @param fileOrDir file or directory to be deleted * @return <code>true</code> if specified file or directory has been * deleted; <code>false</code> otherwise */ public static boolean doDeleteFileOrDir(File fileOrDir) { if (fileOrDir.isDirectory() && !doEmptyDir(fileOrDir)) { return false; } return fileOrDir.delete(); } /** * Removes all the files contained in specified directory. * * @param dir directory to be made empty * @return <code>true</code> if the directory has been made empty; * <code>false</code> otherwise */ public static boolean doEmptyDir(File dir) { File[] children = dir.listFiles(); if (children == null) { return false; } for (int i = 0; i < children.length; ++i) { File child = children[i]; if (child.isDirectory() && !doEmptyDir(child)) { return false; } if (!child.delete()) { return false; } } return true; } }