Java读取resource文件/路径的几种方式


有时候想获取放在工程resources 文件下的文件路径,下面是几种方法:

1.

String fileName = this.getClass().getClassLoader().getResource("文件名").getPath();//获取文件路径  
String fileUtl = this.getClass().getResource("文件名").getFile();

示例路径结果:/E:/idea_work/sofn-qry-web/target/classes/CityJson.js

2.

File directory = new File("");//参数为空
String courseFile = directory.getCanonicalPath()//标准的路径 ;
String author =directory.getAbsolutePath()//绝对路径;
示例路径结果:E:\idea_work\sofn-qry-web



原文:https://blog.csdn.net/oschina_40188932/article/details/78833754


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM