Here you can find the source of renameCanDelete()
private static boolean renameCanDelete() throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { private static boolean rcdDone = false; private static boolean rcdValue; private static boolean renameCanDelete() throws IOException { if (rcdDone) return rcdValue; File a = null;/*from w w w.ja va 2 s. c om*/ File b = null; try { a = File.createTempFile("java-rename-check-", ""); b = File.createTempFile("java-rename-check-", ""); rcdValue = a.renameTo(b); rcdDone = true; } finally { if (a != null) a.delete(); if (b != null) b.delete(); } return rcdValue; } public static boolean delete(File f) { if (f.isFile()) return f.delete(); else if (f.isDirectory()) { boolean b = clearDir(f); b &= f.delete(); 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; } }