Java File Path Delete deleteFile(String filePath)

Here you can find the source of deleteFile(String filePath)

Description

delete File

License

Apache License

Declaration

public static boolean deleteFile(String filePath) 

Method Source Code

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

import java.io.File;

import java.io.IOException;

public class Main {
    public static boolean deleteFile(String filePath) {
        if (!checkFile(filePath, false)) {
            return true;
        }/*from   w w  w . j  a  v a2  s  .  com*/
        File f = new File(filePath);
        return f.delete();
    }

    public static boolean checkFile(String file, boolean create) {
        File f = new File(file);

        if (f.getParent() != null) {
            File fpath = new File(f.getParent());
            if (!fpath.exists()) {
                if (create) {
                    fpath.mkdirs();
                } else {
                    return false;
                }
            }
        }
        if (!f.exists()) {
            if (create) {
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    return false;
                }
            } else {
                return false;
            }
        }
        return true;
    }
}

Related

  1. deleteFile(String filePath)
  2. deleteFile(String filePath)
  3. deleteFile(String filePath)
  4. deleteFile(String filePath)
  5. deleteFile(String filePath)
  6. deleteFile(String filePath)
  7. deleteFile(String filePath)
  8. deleteFile(String filePathAndName)
  9. deleteFile(String filePathName)