jsp教程 目錄 檔案操作
file file1 = new file ("c:tempmynote.txt"); // in windows
file file2 = new file ("/tmp/mynote.txt"); // in linux/unix
檢測檔案路徑
import java.io.file;
public class mainclass {
public static void main(string[] a) {
file myfile = new file("c:" + file.separator + "jdk1.5.0" +
file.separator, "file.java");
system.out.println(myfile.getname());
system.out.println(myfile.getpath());
}
}
擷取遠程圖片
import java.io.file;
import java.net.uri;
public class mainclass {
public static void main(string[] a) throws exception {
file remotefile = new file(new uri("file:///index.htm"));
}
}
上級目錄
import java.io.file;
public class mainclass {
public static void main(string[] a) {
file myfile = new file("c:" + file.separator + "jdk1.5.0" +
file.separator, "file.java");
system.out.println(myfile.getparent());
system.out.println(myfile);
}
}
判斷是否為目錄
import java.io.file;
public class mainclass {
public static void main(string[] a) {
file myfile = new file("c:" + file.separator + "jdk1.5.0" +
file.separator, "file.java");
system.out.println(myfile.isdirectory());
}
}
是否為檔案
import java.io.file;
public class mainclass {
public static void main(string[] a) {
file myfile = new file("c:" + file.separator + "jdk1.5.0" +
file.separator, "file.java");
system.out.println(myfile.isfile());
}
}