Java Utililty Methods Directory Clear

List of utility methods to do Directory Clear

Description

The list of methods to do Directory Clear are organized into topic(s).

Method

voidcleanDirectory(String dirPath)
clean Directory
cleanDirectory(new File(dirPath));
voidclearDirctory(File dir)
clear Dirctory
deleteR(dir, false);
voidclearDirectory(File dir)
clear Directory
for (File f : dir.listFiles()) {
    delete(f);
voidclearDirectory(File dir)
clear Directory
if (!dir.isDirectory()) {
    return;
for (File subFile : dir.listFiles()) {
    if (subFile.isFile()) {
        if (!subFile.delete()) {
            throw new IOException("Can not delete \"" + subFile.getAbsolutePath() + "\".");
    } else if (subFile.isDirectory()) {
        removeDirectory(subFile);
voidclearDirectory(File dir, boolean doTree)
Delete every file within a directory.
String[] fileList = dir.list();
if (fileList == null) { 
    return;
for (int ii = 0; ii < fileList.length; ii++) {
    File subFile = new File(dir, fileList[ii]);
    if (subFile.isDirectory()) {
        if (doTree) {
...
voidclearDirectory(File f)
clear Directory
if (!f.isDirectory()) {
    throw new IllegalArgumentException("Only directory can be cleared."); 
for (File c : f.listFiles()) {
    delete(c);
voidclearDirectory(File f)
clear Directory
if (f.isDirectory()) {
    File[] entries = f.listFiles();
    for (int i = 0; i < entries.length; i++) {
        deleteRecursive(entries[i]);
voidclearDirectory(File src)
Deletes all files in the directory, recursively deleting sub-directories of this directory.
if (src.exists() && src.isDirectory()) {
    for (File file : src.listFiles()) {
        if (file.isDirectory()) {
            deleteRecursive(file);
        } else {
            if (!file.delete()) {
                throw new IOException("Could not delete: " + file);
voidclearDirectory(String absolutePath)
delete all files in specified path
clearDirectory(new File(absolutePath));
voidclearDirectory(String dir)
clear Directory
File f = new File(dir);
if (!f.exists()) {
    throw new IOException("Directory not present or not writable");
if (f.isDirectory()) {
    deleteFolder(f);
} else {
    throw new IOException("Is not a directory");
...