Here you can find the source of deleteFile(String filePath)
public static boolean deleteFile(String filePath)
//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; } }