Spring-读取Classpath下的文件资源

//第一种
File cfgFile = ResourceUtils.getFile("classpath:test.txt");  
//第二种
org.springframework.core.io.Resource fileRource = new ClassPathResource("test.txt");  
fileRource.getFile();//获取文件
fileRource.getInputStream();//获取文件流

但是这有一个有意思的问题,就是在jar包情况下,获取文件会出问题,因为对于系统来说,一个jar包是一个整体,没有办法从一个整体中获取某个文件,只能通过获取流的方式才可以

发布了157 篇原创文章 · 获赞 26 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/u011624903/article/details/67639692