java项目资源路径总结

1.File file = new File("\home\font\simhei.ttf");BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));

2.//D:\JAVA\WmsPdaApi_SUITE\src\main\webapp\String realPath = request.getSession().getServletContext().getRealPath("");

3.//file:/D:/JAVA/WmsPdaApi_SUITE/target/classes/com/vanew/api/wms/controller/URL resource = TestController.class.getResource("");

4.//file:/D:/JAVA/WmsPdaApi_SUITE/target/classes/URL resource = TestController.class.getResource("/");
5.//file:/D:/JAVA/WmsPdaApi_SUITE/target/classes/templates/application.propertiesURL resource = TestController.class.getResource("/templates/application.properties");

6.//file:/D:/JAVA/WmsPdaApi_SUITE/target/classes/URL resource1 = TestController.class.getClassLoader().getResource("");

7.//file:/D:/JAVA/WmsPdaApi_SUITE/target/classes/URL resource1 = TestController.class.getClassLoader().getResource(“application.properties”);

8.///D:/JAVA/WmsPdaApi_SUITE/target/classes/templates/application.propertiesURL resource1 = TestController.class.getClassLoader().getResource(“templates/application.properties”);

9.//null 默认从classpath中找文件(文件放在resources目录下),name不能带“/”,则会抛空指针URL resource1 = TestController.class.getClassLoader().getResource("/templates/application.properties");

10.//file:/D:/JAVA/WmsPdaApi_SUITE/target/classes/com/vanew/api/wms/controller/transfer/TincoWmsTransferController.classURL resource = TestController.class.getResource(“transfer/TincoWmsTransferController.class”);

上一篇:Spring - @ComponentScan包扫描机制


下一篇:自从学了这套框架,性能测试搞定了