java项目资源路径总结
Posted 海绵不老
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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”);
以上是关于java项目资源路径总结的主要内容,如果未能解决你的问题,请参考以下文章
web路径总结与项目部署到Tomcat时资源访问404问题的解决