1 package org.myoodb.core; 25 26 import java.io.*; 27 28 public final class FileHelper 29 { 30 private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(FileHelper.class); 31 32 public static boolean delete(File file) 33 { 34 if (file.delete() == false) 35 { 36 LOGGER.warn("Unable to delete(1): " + file); 37 38 System.gc(); 39 40 if (file.delete() == false) 41 { 42 LOGGER.warn("Unable to delete(2): " + file); 43 44 try 45 { 46 Thread.sleep(100); 47 } 48 catch (InterruptedException e) 49 { 50 } 51 52 return file.delete(); 53 } 54 } 55 56 return true; 57 } 58 59 public static void delete(String name) 60 { 61 File file = new File(name); 62 if (file.exists() == true) 63 { 64 String [] files = file.list(); 65 66 if ((files != null) && (files.length != 0)) 67 { 68 for (int i = 0; i < files.length; i++) 69 { 70 File subfile = new File(name, files[i]); 71 72 if (subfile.isDirectory() == true) 73 { 74 delete(subfile.getPath()); 75 } 76 else 77 { 78 if (delete(subfile) == false) 79 { 80 LOGGER.error("Unable to delete(3): " + subfile); 81 } 82 } 83 } 84 } 85 86 delete(file); 87 } 88 } 89 } 90 | Popular Tags |