笔记:Spring中获取classpath下的文件资源
来源:互联网 发布:java架构师是做什么的 编辑:程序博客网 时间:2024/06/05 04:27
通过Spring工具类获取classpath下的文件资源
1、资源文件不在jar中
File cfgFile = ResourceUtils.getFile("classpath:test.txt");或者org.springframework.core.io.Resource fileRource = new ClassPathResource("test.txt");
获取文件:fileRource.getFile();
获取文件流:fileRource.getInputStream();
2、资源文件在jar中
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
阅读全文
0 0
- 笔记:Spring中获取classpath下的文件资源
- 关于Spring工具类获取classpath下的文件资源
- 笔记:通过Spring工具类获取classpath下的文件资源
- 通过Spring工具类获取classpath下的文件资源--笔记
- Java中获取classpath路径下的资源文件
- spring加载资源文件中classpath*与classpath的区别
- Java中获取classpath路径下的资源文件【ClassLoader.getSystemResource("")获取当前ClassPath的绝对URI路径,还可以以流的形式获取文件】
- Maven项目中获取classpath和资源文件的路径
- Maven项目中获取classpath和资源文件的路径
- Maven项目中获取classpath和资源文件的路径
- Spring资源文件加载时classpath和classpath*的区别
- Spring下classpath与classpath*的区别
- 获取项目中Classpath中的资源路径
- Spring中classpath*:与classpath:的区别
- spring中classpath与classpath*的区别
- Spring中classpath和classpath*的问题
- Spring中classpath*和classpath的区别
- Spring获取资源文件
- HaProxy在CentOS 6安装
- SAX与DOM解析XML
- POJ 1182 食物链 (带权并查集)
- html页面识别当前系统和语言
- 中国大陆开源软件镜像服务站点列表
- 笔记:Spring中获取classpath下的文件资源
- 3. Longest Substring Without Repeating Characters(计算不含重复字符的最长子串的长度)
- SQLITE 自增列
- KVO详解
- android获取屏幕相关信息
- Spring framework、Spring MVC、Apache CXF搭建webService环境
- maven国内镜像--开源中国
- 【报错】ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory
- eclipse在debug模式下总自动跳到ThreadPoolExecutor解决方案