home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- import java.util.Vector;
-
- public class File {
- private String path;
- public static final String separator = System.getProperty("file.separator");
- public static final char separatorChar;
- public static final String pathSeparator;
- public static final char pathSeparatorChar;
-
- public File(String path) {
- if (path == null) {
- throw new NullPointerException();
- } else {
- this.path = path;
- }
- }
-
- public File(String path, String name) {
- this(path != null ? path + separator + name : name);
- }
-
- public File(File dir, String name) {
- this(dir.getPath(), name);
- }
-
- public String getName() {
- int index = this.path.lastIndexOf(separatorChar);
- return index < 0 ? this.path : this.path.substring(index + 1);
- }
-
- public String getPath() {
- return this.path;
- }
-
- public String getAbsolutePath() {
- if (this.isAbsolute()) {
- return this.path;
- } else {
- String key = "user.dir";
- return System.getProperty(key) + separator + this.path;
- }
- }
-
- public String getParent() {
- int index = this.path.lastIndexOf(separatorChar);
- return index <= 0 ? null : this.path.substring(0, index);
- }
-
- private native boolean exists0();
-
- private native boolean canWrite0();
-
- private native boolean canRead0();
-
- private native boolean isFile0();
-
- private native boolean isDirectory0();
-
- private native long lastModified0();
-
- private native long length0();
-
- private native boolean mkdir0();
-
- private native boolean renameTo0(File var1);
-
- private native boolean delete0();
-
- private native String[] list0();
-
- public boolean exists() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(this.path);
- }
-
- return this.exists0();
- }
-
- public boolean canWrite() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkWrite(this.path);
- }
-
- return this.canWrite0();
- }
-
- public boolean canRead() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(this.path);
- }
-
- return this.canRead0();
- }
-
- public boolean isFile() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(this.path);
- }
-
- return this.isFile0();
- }
-
- public boolean isDirectory() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(this.path);
- }
-
- return this.isDirectory0();
- }
-
- public native boolean isAbsolute();
-
- public long lastModified() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(this.path);
- }
-
- return this.lastModified0();
- }
-
- public long length() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(this.path);
- }
-
- return this.length0();
- }
-
- public boolean mkdir() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkWrite(this.path);
- }
-
- return this.mkdir0();
- }
-
- public boolean renameTo(File dest) {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkWrite(this.path);
- security.checkWrite(dest.path);
- }
-
- return this.renameTo0(dest);
- }
-
- public boolean mkdirs() {
- if (this.mkdir()) {
- return true;
- } else {
- String parent = this.getParent();
- return parent != null && (new File(parent)).mkdirs() && this.mkdir();
- }
- }
-
- public String[] list() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(this.path);
- }
-
- return this.list0();
- }
-
- public String[] list(FilenameFilter filter) {
- String[] names = this.list();
- Vector v = new Vector();
-
- for(int i = 0; i < names.length; ++i) {
- if (filter == null || filter.accept(this, names[i])) {
- v.addElement(names[i]);
- }
- }
-
- String[] files = new String[v.size()];
- v.copyInto(files);
- return files;
- }
-
- public boolean delete() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkDelete(this.path);
- }
-
- return this.delete0();
- }
-
- public int hashCode() {
- return this.path.hashCode() ^ 1234321;
- }
-
- public boolean equals(Object obj) {
- return obj != null && obj instanceof File ? this.path.equals(((File)obj).path) : false;
- }
-
- public String toString() {
- return this.getPath();
- }
-
- static {
- separatorChar = separator.charAt(0);
- pathSeparator = System.getProperty("path.separator");
- pathSeparatorChar = pathSeparator.charAt(0);
- }
- }
-