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

voiddeleteDir(File dir)
Deletes the specified dir recursively, throwing a RuntimeException if the delete fails.
deleteDirContent(dir);
if (!dir.delete()) {
    throw new RuntimeException("Directory " + dir.getAbsolutePath() + " can't be deleted.");
booleandeleteDir(File dir)
delete Dir
if (!dir.isDirectory()) {
    return false;
for (File file : dir.listFiles()) {
    if (file.isDirectory()) {
        try {
            if (file.getCanonicalFile().getParentFile().equals(dir.getCanonicalFile())) {
                deleteDir(file);
...
booleandeleteDir(File dir)
delete Dir
if (dir == null)
    return false;
if (dir.isDirectory()) {
    String[] children = dir.list();
    for (int i = 0; i < children.length; i++) {
        boolean success = deleteDir(new File(dir, children[i]));
        if (!success) {
            return false;
...
booleandeleteDir(File dir)
delete Dir
boolean deleted = dir.delete();
if (!deleted) {
    String[] list = dir.list();
    if (list != null) {
        for (int i = 0; i < list.length; i++) {
            deleteDir(new File(dir, list[i]));
    deleted = dir.delete();
return deleted;
voiddeleteDir(File dir)
delete Dir
if (!dir.isDirectory()) {
    System.err.println("Tried to delete a directory but file is not a directory: " + dir.getAbsolutePath());
    return;
File[] f = dir.listFiles();
if (f == null) {
    return;
for (int i = 0; i < f.length; i++) {
    File file = f[i];
    if (file.isDirectory()) {
        deleteDir(file);
    } else {
        file.delete();
dir.delete();
booleandeleteDir(File dir)
Delete the specified directory, including all of its contents and subdirectories recursively.
String files[] = dir.list();
if (files == null) {
    files = new String[0];
for (int i = 0; i < files.length; i++) {
    File file = new File(dir, files[i]);
    if (file.isDirectory()) {
        deleteDir(file);
...
voiddeleteDir(File dir)
delete Dir
if (dir.isFile())
    throw new IOException("IOException -> BadInputException: not a directory.");
File[] files = dir.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        if (file.isFile()) {
            file.delete();
...
booleandeleteDir(File dir)
delete Dir
try {
    return ((deleteFromDir(dir)) && (dir.delete()));
} catch (Exception e) {
    e.printStackTrace();
return false;
booleandeleteDir(File dir)
delete Dir
if (dir == null)
    return false;
File candir;
try {
    candir = dir.getCanonicalFile();
} catch (IOException e) {
    return false;
if (!candir.equals(dir.getAbsoluteFile()))
    return false;
File files[] = candir.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        boolean deleted = !file.delete();
        if (deleted && file.isDirectory())
            deleteDir(file);
return dir.delete();
booleandeleteDir(File dir)
delete Dir
if (dir.isDirectory()) {
    String[] children = dir.list();
    for (int i = 0; i < children.length; i++) {
        boolean success = deleteDir(new File(dir, children[i]));
        if (!success) {
            return false;
return dir.delete();