Here you can find the source of deleteFile(String fileName)
public static boolean deleteFile(String fileName)
//package com.java2s; import java.io.File; public class Main { public static boolean deleteFile(String fileName) { File file = new File(fileName); if (file.exists() && file.isFile()) { return file.delete(); }/* w w w .ja v a 2 s . c om*/ return false; } public static boolean delete(String fileName) { File file = new File(fileName); if (!file.exists()) { return false; } else { if (file.isFile()) { return deleteFile(fileName); } else { return deleteDirectory(fileName); } } } public static boolean deleteDirectory(String dir) { if (!dir.endsWith(File.separator)) { dir = dir + File.separator; } File dirFile = new File(dir); if (!dirFile.exists() || !dirFile.isDirectory()) { return false; } boolean flag = true; File[] files = dirFile.listFiles(); int filesLength = files.length; for (int i = 0; i < filesLength; i++) { if (files[i].isFile()) { flag = deleteFile(files[i].getAbsolutePath()); if (!flag) { break; } } else if (files[i].isDirectory()) { flag = deleteDirectory(files[i].getAbsolutePath()); if (!flag) { break; } } } if (!flag) { return false; } return dirFile.delete(); } }