Java File Delete delete(File f)

Here you can find the source of delete(File f)

Description

delete

License

Apache License

Declaration

public static boolean delete(File f) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {

    public static boolean delete(File f) {
        if (f.isFile())
            return f.delete();
        else if (f.isDirectory()) {
            boolean b = clearDir(f);
            b &= f.delete();/*from w  w w .j a  va2  s  .  c om*/
            return b;
        } else
            return false;
    }

    public static boolean isFile(String fileName) {
        File testFile = new File(fileName);

        if ((testFile.exists()) && (testFile.isFile())) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isDirectory(String fileName) {
        File testFile = new File(fileName);

        if ((testFile.exists()) && (testFile.isDirectory())) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean clearDir(File dir) {
        if (!dir.isDirectory())
            return false;
        File[] files = dir.listFiles();
        if (files == null || files.length == 0)
            return true;
        boolean cleared = true;
        for (File sub : files) {
            cleared &= delete(sub);
        }
        return cleared;
    }
}

Related

  1. delete(File current)
  2. delete(File dir)
  3. delete(File dir)
  4. delete(File dir)
  5. delete(File f)
  6. delete(File f)
  7. delete(File f)
  8. delete(File f)
  9. delete(File f)