Java Utililty Methods File Path Delete

List of utility methods to do File Path Delete

Description

The list of methods to do File Path Delete are organized into topic(s).

Method

booleandelete(String filePath, boolean recursive)
delete
File file = new File(filePath);
if (!file.exists()) {
    return true;
if (!recursive || !file.isDirectory())
    return file.delete();
String[] contents = file.list();
if (contents != null) {
...
booleandelete(String path)
Attempts to delete the File with the given path.
return new File(path).delete();
voiddelete(String path)
delete
File f = new File(path);
if (!f.exists())
    return;
if (f.isDirectory()) {
    if (f.listFiles().length == 0) {
        f.delete();
    } else {
        File delFile[] = f.listFiles();
...
booleandelete(String path)
Delete the file or directory at the supplied path.
if (path == null || path.trim().length() == 0)
    return false;
return delete(new File(path));
booleandelete(String path)
Method to delete a file or a directory and all it's contents if there are any.
boolean rc = true;
File file = new File(path);
if (!file.exists()) {
    throw new IOException("Unable to delete " + path + ". Path does not exist.");
if (file.isFile()) {
    if (file.delete()) {
        return true;
...
booleandeleteAll(File path)
delete All
boolean ok = true;
File[] children = path.listFiles();
if (children != null) {
    for (File child : children) {
        ok = deleteAll(child);
        if (!ok) {
            break;
return ok && path.delete();
voiddeleteAll(File path)
delete All
if (!path.exists())
    return;
if (path.isFile()) {
    path.delete();
    return;
File[] files = path.listFiles();
for (int i = 0; i < files.length; i++) {
...
voiddeleteAll(File path)
delete all files and folders under this path
if (path.isDirectory()) {
    for (File f : path.listFiles()) {
        deleteAll(f);
    if (path.listFiles().length == 0) {
        path.delete();
} else {
...
booleandeleteAllFile(final File dir)
delete All File
boolean deleted = false;
if (dir.exists()) {
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteAllFile(files[i]);
        } else {
            deleted = files[i].delete();
...
voiddeleteAllFile(String directory)
delete all file
List<File> fileList = new ArrayList<File>();
File directoryFile = new File(directory);
Queue<File> queue = new ConcurrentLinkedQueue<File>();
queue.add(directoryFile);
while (!queue.isEmpty()) {
    File file = queue.poll();
    if (file.isDirectory()) {
        File[] fileArray = file.listFiles();
...