|------磁盘目录:
1.获得j2ee项目根目录WebRoot所在的磁盘位置
request.getRealPath("/")
如:D:\MyWork\humanmanage\WebRoot\
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
System.out.println(test.class.getClassLoader().getResource(""));
System.out.println(ClassLoader.getSystemResource(""));
System.out.println(test.class.getResource(""));
System.out.println(test.class.getResource("/"));
System.out.println(new File("").getAbsolutePath());
System.out.println(System.getProperty("user.dir"));
输出结果:
file:/D:/MyWork/webcount/WebRoot/WEB-INF/classes/
file:/D:/MyWork/webcount/WebRoot/WEB-INF/classes/
file:/D:/MyWork/webcount/WebRoot/WEB-INF/classes/
file:/D:/MyWork/webcount/WebRoot/WEB-INF/classes/com/sinoMerica/count/
file:/D:/MyWork/webcount/WebRoot/WEB-INF/classes/
D:\MyWork\webcount
D:\MyWork\webcount
-----------------------------------------------------------------------------------------
|------相对目录: