List of utility methods to do Delete File
void | deleteFile(File file) delete File if (!file.exists()) throw new FileNotFoundException(file.getAbsolutePath()); if (!file.delete()) { throw new IOException("Delete operation failed when deleting: " + file); |
void | deleteFile(File file) Delete the a file or a directory. if (file.isDirectory()) {
emptyDirectory(file);
file.delete();
|
void | deleteFile(File file) delete File if (file != null) { for (File childFile : file.listFiles()) { if (childFile.isDirectory()) { deleteFile(childFile); } else { if (!childFile.delete()) { throw new IOException(); if (!file.delete()) { throw new IOException(); |
int | deleteFile(File file) delete File if (file == null) { return -1; if (file.exists()) { if (file.isFile()) { if (file.delete()) { return 0; if (file.isDirectory()) { File[] subFiles = file.listFiles(); if (subFiles != null) { for (File subFile : subFiles) { deleteFile(subFile); if (file.delete()) { return 0; return -1; } else { return -1; |
void | deleteFile(File file) delete File if (file == null || !file.exists()) { return; if (!file.delete()) { throw new IOException("Can't delete file : " + file.getPath()); |
boolean | deleteFile(File file) delete File if (file == null) return false; return file.delete(); |
void | deleteFile(File file) delete File if (!file.delete() && file.exists()) { throw new IllegalStateException("Could not delete: " + file.getPath()); |
boolean | deleteFile(File file) Deletes the file provided. if (!file.exists()) return false; File[] files = file.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File childFile = files[i]; if (childFile.equals(file)) continue; ... |
boolean | deleteFile(File file) Accommodate Windows bug: If the delete does not work, call System.gc() , wait a little and try again.
if (file.isDirectory()) { throw new IOException("File " + file + " isn't a file."); if (!file.delete()) { if (System.getProperty("os.name").equalsIgnoreCase("windows")) { file = file.getCanonicalFile(); System.gc(); try { Thread.sleep(10); return file.delete(); } catch (InterruptedException ex) { return file.delete(); return true; |
boolean | deleteFile(File file) delete File if (!file.exists()) { return true; int count = 0; boolean deleted; do { deleted = file.delete(); if (!deleted) { ... |