Here you can find the source of recursiveDelete(File folder)
Parameter | Description |
---|---|
folder | a parameter |
public static boolean recursiveDelete(File folder)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**/*from ww w . ja va2 s .c o m*/ * fully delete a folder * * @param folder * @return whether deletion was successful */ public static boolean recursiveDelete(File folder) { boolean ret = _recursiveDelete(folder); clean(); return ret; } private static boolean _recursiveDelete(File folder) { clean(); /* windows needs this */ if (folder.isFile()) { return folder.delete(); } else { String[] l = folder.list(); if (l != null) { for (String aL : l) { if (recursiveDelete(new File(folder.getPath(), aL)) == false) { System.err.println("deleting " + aL + " in " + folder.getPath() + " failed!"); return false; } } } clean(); return folder.delete(); } } private static void clean() { System.gc(); try { Thread.sleep(10); } catch (InterruptedException e) { } System.gc(); try { Thread.sleep(10); } catch (InterruptedException e) { } System.gc(); } }