1 23 24 package com.sun.enterprise.tools.verifier; 25 26 import java.io.BufferedReader ; 27 import java.io.File ; 28 import java.io.FileReader ; 29 30 36 public class TmpCleaner { 37 38 private final static String TMPDIR = System.getProperty("java.io.tmpdir"); 39 40 public void run() { 41 42 try { 44 String cleandirs = TMPDIR + File.separator + "cleandirs.txt"; File tmpfile = new File (cleandirs); 46 if (!tmpfile.exists()) 47 return; 48 BufferedReader br = new BufferedReader (new FileReader (cleandirs)); 49 50 try { 51 do { 52 String str = br.readLine(); 53 String file = TMPDIR + File.separator + str; 54 File toDelete = new File (file); 55 deleteFile(toDelete); 56 toDelete.deleteOnExit(); 57 } while (br.ready()); 58 } catch (Exception e) { 59 } 60 61 62 br.close(); 63 File f = new File (cleandirs); 64 f.delete(); 65 } catch (Exception e) { 66 } 67 } 68 69 private void deleteFile(File p_file) { 70 String FILE_SEPARATOR = System.getProperty("file.separator"); 71 if (p_file.isDirectory()) { 73 String [] dirList = p_file.list(); 74 for (int i = 0; i < dirList.length; i++) { 75 76 File aFile = new File ( 77 p_file.getPath() + FILE_SEPARATOR + dirList[i]); 78 if (aFile.isDirectory()) { 79 deleteFile(aFile); 80 } 81 aFile.delete(); 82 } 83 } 84 p_file.delete(); 85 } 86 87 88 public static void main(String [] args) { 89 try { 90 TmpCleaner t = new TmpCleaner(); 91 System.gc(); 92 t.run(); 93 } catch (Exception e) { 94 } 95 System.exit(0); 96 } 97 98 } 99 | Popular Tags |