List of utility methods to do Delete File or Directory
void | deleteFileOrDirectoryRecursive(String dir) Recurse through children deleting all as we go File theDir = new File(dir); if (theDir != null) { deleteFileOrDirectoryRecursive(theDir); |
boolean | deleteFileOrDirOnExit(File filehandle) Delete file or folder recursively on exit of the program if (filehandle.isDirectory()) { String[] children = filehandle.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteFileOrDir(new File(filehandle, children[i])); if (!success) { return false; filehandle.deleteOnExit(); return true; |
void | deleteFileOrFolder(File fileOrFolder) Delete the file or folder given in fileOrFolder .
File[] files = fileOrFolder.listFiles(); if (files != null) { int idx = files.length; while (--idx >= 0) deleteFileOrFolder(files[idx]); fileOrFolder.delete(); |