1、获取WEB-INF文件夹下的文件
/C:/Users/Administrator/Workspaces/MyEclipse%2010/day_38_spring_hibernate/WebRoot/WEB-INF/classes/com/itheima/test/
1 String path=TestHibernate.class.getResource("").getPath(); 2 System.out.println(path);
其对应的文件位置是
2、获取WEB-INF文件夹下的文件
/C:/Users/Administrator/Workspaces/MyEclipse%2010/day_38_spring_hibernate/WebRoot/WEB-INF/classes/
String path=TestHibernate.class.getResource("/").getPath();
其对于的文件位置是
3.getClassLoader和第二种的一样
/C:/Users/Administrator/Workspaces/MyEclipse%2010/day_38_spring_hibernate/WebRoot/WEB-INF/classes/
String path=TestHibernate.class.getClassLoader().getResource("").getPath(); System.out.println(path);
4、
file:/C:/Users/Administrator/Workspaces/MyEclipse%2010/day_38_spring_hibernate/WebRoot/WEB-INF/lib/hibernate3.jar!/
String path=TestHibernate.class.getClassLoader().getResource("/").getPath();
System.out.println(path);
5、Servlet的getRealPath
String path=getServletContext().getRealPath("/timeSequence.xlsx");
G:\BaiduYunDownload\apache-tomcat-6.0.29\apache-tomcat-6.0.29\webapps\Test_Polyfit\timeSequence.xlsx
定位的是
的项目路径下,然后可以去写WEB-INF/文件夹中找东东
需要注意的是在这里无论加不加"/",定位的都是tomcat的webapps\Test_Polyfit\
getRealPath("/timeSequence.xlsx");