24 Sept 2012

how to force to delete a Directory in java

/* how to force to delete a Directory in java, delete a folder in java code,force to delete all files from a folder in java code */

java.io.File fin = new java.io.File("F:/folder name/");
    java.io.File[] finlist = fin.listFiles();       
    for (int n = 0; n < finlist.length; n++) 
      {
        if (finlist[n].isFile()) 
         {
        System.gc();
        java.lang.Thread.sleep(2000);
        finlist[n].delete();
        }
    } 

or

org.apache.commons.io.FileUtils.deleteDirectory(java.io.File directoryname) throws IOException

or

java.io.File fin = new java.io.File("F:/folder name/");
for (java.io.File file : fin.listFiles()) 
{
    org.apache.commons.io.FileDeleteStrategy.FORCE.delete(file); //throws IOException
}


For ieee projects visit our site here

0 comments:

Post a Comment