一、资源文件不在jar中 java
File cfgFile = ResourceUtils.getFile("classpath:test.txt"); 或者 org.springframework.core.io.Resource fileRource = new ClassPathResource("test.txt");获取文件:fileRource.getFile();
org.springframework.core.io.Resource fileRource = new ClassPathResource("test.txt");
获取文件流:fileRource.getInputStream();
注:无论是文件系统中的类资源,仍是JAR中的类资源文件,均可以以流的形式读取
参考:
陈雄华:《使用以下方式读取JAR中的文件出错》http://stamen.iteye.com/blog/1485531
http://blog.csdn.net/liu251/article/details/2899023
如何读取JAR包中的资源文件(如XML、TXT等) :http://blog.csdn.net/liu251/article/details/4057140
spring