jsp 目录 文件操作
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());
}
}
补充:Jsp教程,J2EE/EJB/服务器