KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > mog > io > File


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package se.mog.io;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URI JavaDoc;
22
23 /**
24  * @author <a HREF="mailto:drftpd@mog.se">Morgan Christiansson</a>
25  *
26  * To change the template for this generated type comment go to
27  * Window>Preferences>Java>Code Generation>Code and Comments
28  */

29 public class File extends java.io.File JavaDoc {
30     private static FileSystem fs = FileSystem.getFileSystem();
31
32     /**
33      * @param pathname
34      */

35     public File(String JavaDoc pathname) {
36         super(pathname);
37     }
38     public File(java.io.File JavaDoc file) {
39         super(file.getPath());
40     }
41     /**
42      * @param parent
43      * @param child
44      */

45     public File(String JavaDoc parent, String JavaDoc child) {
46         super(parent, child);
47     }
48
49     /**
50      * @param parent
51      * @param child
52      */

53     public File(java.io.File JavaDoc parent, String JavaDoc child) {
54         super(parent, child);
55     }
56
57     /**
58      * @param uri
59      */

60     public File(URI JavaDoc uri) {
61         super(uri);
62     }
63     /**
64      * Returns all mounted volumes on the system, this includes file system roots.
65      *
66      * @see java.io.File#listRoots()
67      */

68     public static File[] listMounts() throws IOException JavaDoc {
69         return fs.listMounts();
70     }
71     
72     public long getDiskSpaceAvailable() {
73         return fs.getDiskFreeSpace(this).freeBytes;
74     }
75
76     public long getDiskSpaceCapacity() {
77         return fs.getDiskFreeSpace(this).totalBytes;
78     }
79     
80     public boolean isSymbolicLink() throws IOException JavaDoc {
81         return !getCanonicalPath().equals(getAbsolutePath());
82     }
83     /**
84      * Works exactly like <code>{@link java.io.File#delete()}</code> but has the added funcionality of working recursively.
85      * @see java.io.File#delete()
86      */

87     public boolean deleteRecursive() {
88         if(isDirectory()) {
89             java.io.File JavaDoc files[] = listFiles();
90             for (int i = 0; i < files.length; i++) {
91                 File file = new File(files[i]);
92                 file.deleteRecursive();
93             }
94         }
95         return super.delete();
96     }
97
98 }
99
Popular Tags