2007-07-27 00:06:05 +00:00
|
|
|
package java.io;
|
|
|
|
|
|
|
|
public class File {
|
2007-08-15 01:14:55 +00:00
|
|
|
static {
|
|
|
|
System.loadLibrary("natives");
|
|
|
|
}
|
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
private final String path;
|
|
|
|
|
|
|
|
public File(String path) {
|
|
|
|
if (path == null) throw new NullPointerException();
|
|
|
|
this.path = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public File(String parent, String child) {
|
|
|
|
this(parent + "/" + child);
|
|
|
|
}
|
|
|
|
|
|
|
|
public File(File parent, String child) {
|
|
|
|
this(parent.getPath() + "/" + child);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
int index = path.lastIndexOf("/");
|
|
|
|
if (index >= 0) {
|
|
|
|
return path.substring(index + 1);
|
|
|
|
} else {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPath() {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2007-08-28 23:39:21 +00:00
|
|
|
public String getParent() {
|
|
|
|
int index = path.lastIndexOf("/");
|
|
|
|
if (index >= 0) {
|
|
|
|
return path.substring(0, index);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public File getParentFile() {
|
|
|
|
String s = getParent();
|
|
|
|
return (s == null ? null : new File(s));
|
|
|
|
}
|
|
|
|
|
2007-07-27 02:39:53 +00:00
|
|
|
private static native String toCanonicalPath(String path);
|
|
|
|
|
|
|
|
public String getCanonicalPath() {
|
|
|
|
return toCanonicalPath(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
public File getCanonicalFile() {
|
|
|
|
return new File(getCanonicalPath());
|
|
|
|
}
|
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
private static native String toAbsolutePath(String path);
|
|
|
|
|
|
|
|
public String getAbsolutePath() {
|
|
|
|
return toAbsolutePath(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native long length(String path);
|
|
|
|
|
|
|
|
public long length() {
|
|
|
|
return length(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native boolean exists(String path);
|
|
|
|
|
|
|
|
public boolean exists() {
|
|
|
|
return exists(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native void mkdir(String path);
|
|
|
|
|
|
|
|
public void mkdir() {
|
|
|
|
mkdir(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native void createNewFile(String path);
|
|
|
|
|
|
|
|
public void createNewFile() {
|
|
|
|
createNewFile(path);
|
|
|
|
}
|
2007-09-12 01:13:05 +00:00
|
|
|
|
|
|
|
public static native boolean delete(String path);
|
|
|
|
|
|
|
|
public boolean delete() {
|
|
|
|
return delete(path);
|
|
|
|
}
|
2007-07-27 00:06:05 +00:00
|
|
|
}
|