Java Utililty Methods File Delete

List of utility methods to do File Delete

Description

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

Method

voidclearFile(File file)
clear File
file.delete();
file.createNewFile();
voidclearFile(String directory)
clear File
try {
    FileWriter outFile = new FileWriter(directory);
    PrintWriter out = new PrintWriter(outFile);
    out.print("");
    out.close();
} catch (IOException e) {
    e.printStackTrace();
voidclearFile(String pFileName)
clear File
try {
    new FileOutputStream(pFileName);
} catch (FileNotFoundException e) {
    e.printStackTrace();
voidclearFileOrDir(File file)
Clear directory
if (!file.exists()) {
    return;
if (file.isFile()) {
    file.delete();
    return;
File[] children = file.listFiles();
...
booleandelete(File aFile)
deletes a file from the file system; for directories, recurse the subdirectories and delete them as well
if (aFile == null)
    return true;
if (aFile.isDirectory()) {
    File[] files = aFile.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (!delete(files[i]))
                return false;
...
voiddelete(File classDir)
delete
File[] files = classDir.listFiles();
if (files != null) {
    for (File f : files) {
        delete(f);
classDir.delete();
booleandelete(File current)
delete
boolean status = true;
if (current.isDirectory())
    for (File sub : current.listFiles())
        status &= delete(sub);
if (current.exists() && (!current.delete()))
    return false;
return status;
voiddelete(File dir)
delete
if (dir.exists() && dir.isDirectory()) {
    for (File file : dir.listFiles()) {
        if (file.isDirectory()) {
            delete(file);
        file.delete();
voiddelete(File dir)
delete
if (!dir.isDirectory()) {
    dir.delete();
    return;
String[] entries = dir.list();
for (String s : entries) {
    File currentFile = new File(dir.getPath(), s);
    if (currentFile.isDirectory()) {
...
booleandelete(File dir)
Delete file or directory.
return deleteContents(dir) && dir.delete();