/** * Recursively delete all the files in a directory and the directory. * * @throws RuntimeException * iff there is file that can not be deleted. */ public static void delete(File f) throws IOException { // determine if the file/directory exists.. if (f.exists()) { final String msg = "Failed to delete: " + f; // determine if this is a directory or file.. if (f.isDirectory()) { // delete all the files/directories File[] fs = f.listFiles(); for (int x = 0; x < fs.length; x++) { delete(fs[x]); } // delete the directory if (!f.delete()) { throw new IOException(msg); } } else if (f.isFile() && !f.delete()) { // failed to delete file.. throw new IOException(msg); } } }
/** * Recursively delete all the files in a directory and the directory. * * @param file * the file to delete * @throws RuntimeException * if there is file that can not be deleted. */ public static void delete(final File file) throws IOException { // determine if the file/directory exists.. if (file.exists()) { final String msg = "Failed to delete: " + file; // determine if this is a directory or file.. if (file.isDirectory()) { // delete all the files/directories File[] fs = file.listFiles(); for (int x = 0; x < fs.length; x++) { delete(fs[x]); } // delete the directory if (!file.delete()) { throw new IOException(msg); } } else if (file.isFile() && !file.delete()) { // failed to delete file.. throw new IOException(msg); } } }
/** * Recursively delete all the files in a directory and the directory. * * @param file * the file to delete * @throws RuntimeException * if there is file that can not be deleted. */ public static void delete(final File file) throws IOException { // determine if the file/directory exists.. if (file.exists()) { final String msg = "Failed to delete: " + file; // determine if this is a directory or file.. if (file.isDirectory()) { // delete all the files/directories File[] fs = file.listFiles(); for (int x = 0; x < fs.length; x++) { delete(fs[x]); } // delete the directory if (!file.delete()) { throw new IOException(msg); } } else if (file.isFile() && !file.delete()) { // failed to delete file.. throw new IOException(msg); } } }