KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > EEG > fileutil > Delete


1 /*
2  * Copy.java
3  *
4  * Created on 10. duben 2002, 12:41
5  */

6
7 package SOFA.Connector.EEG.fileutil;
8
9 /**
10  *
11  * @author ghort
12  * @version
13  */

14 public class Delete {
15
16     /** Creates new Copy */
17     private Delete() {
18     }
19
20     public static void delete(java.io.File JavaDoc path) throws DeleteException {
21         if (path.isDirectory()) {
22             deleteDirectory(path);
23         } else {
24             deleteFile(path);
25         }
26     }
27     
28     protected static void deleteDirectory(java.io.File JavaDoc path) throws DeleteException {
29         java.io.File JavaDoc[] list=path.listFiles();
30         for (int i=0;i<list.length;i++) {
31             if (list[i].isDirectory()) {
32                 deleteDirectory(list[i]);
33                 if (!list[i].delete()) {
34                     throw new DeleteException("Can't delete directory '"+list[i]+"'.");
35                 }
36             } else {
37                 deleteFile(list[i]);
38             }
39         }
40     }
41     
42     protected static void deleteFile(java.io.File JavaDoc path) throws DeleteException {
43         if (!path.delete()) {
44             throw new DeleteException("Can't delete file '"+path+"'.");
45         }
46     }
47 }
48
Popular Tags