springboot-项目获取resources下文件的方法
spring项目获取resources下文件的方法
最近写读取模板文件做一些后续的处理,将文件放在了项目的resources 下,发现了一个好用的读取方法:

比如上边是你需要读取的文件:
读取的方法如下:
//File file = ResourceUtils.getFile("classpath:templates/b_dfd.txt");
File file = ResourceUtils.getFile("classpath:templates");
if(file.exists()){
File[] files = file.listFiles();
if(files != null){
for(File childFile:files){
System.out.println(childFile.getName());
}
}
}
上边的 ResourceUtils.getFile() 方法可以获取到resources 下的文件。
前几天发现,这个方法在linux系统下没用,希望大家注意一下。
springboot-项目获取resources下文件的方法的更多相关文章
- Maven项目读取resources下文件的路径问题(getClassLoader的作用)
读取resources下文件的方法 网上有问答如下:问: new FileInputStream("src/main/resources/all.properties") new ...
- springboot-项目获取resources下文件碰到的问题(classPath下找不到文件和文件名乱码)
项目是spring-boot + spring-cloud 并使用maven 管理依赖.在springboot+maven项目下怎么读取resources下的文件实现文件下载? 怎么获取resourc ...
- springboot项目获取resource下的文件
package com.expr.exceldemo; import org.springframework.core.io.ClassPathResource; public class Test ...
- idea 下获取路径下文件的方法
想读取resouce/temp下的test.txt文件.方式一:File sourceFile = ResourceUtils.getFile("classpath:temp/test.tx ...
- SpringBoot项目获取ApplicationContext来GetBean的方法
一.简介 我们开发时,经常遇到有些实例需要动态创建,比如有构造函数的组件等.这时候,Spring时我们有ClassPathXmlApplicationContext,但是在Spring Boot时,我 ...
- java(包括springboot)读取resources下文件方式
1.使用项目内路径读取,该路径只在开发工具中显示,类似:src/main/resources/resource.properties.只能在开发工具中使用,部署之后无法读取.(不通用) File fi ...
- Maven项目读取resources下文件的路径
要取编译后的路径,而不是你看到的src/main/resources的路径.如下: URL url = 类名.class.getClassLoader().getResource("conf ...
- Spring Boot 获取 java resources 下文件
Spring Boot 获取 java resources 下文件 Spring Boot 获取 resources 目录下的目录(例:获取 resources 目录下的 template 目录): ...
- springboot打成jar后获取classpath下文件失败
原文链接:https://blog.csdn.net/qq_18748427/article/details/78606432 springboot打成jar后获取classpath下文件失败 使用如 ...
随机推荐
- Python面试题分享——图迹信息科技
本帖最后由 逆风TO 于 2019-5-23 14:25 编辑 公司名称:西安图迹信息科技有限公司 公司地址:锦业路69号创业研发园瞪羚谷A座9层 主营概况:2013年成立,大数据应用工程中心,为五大 ...
- python线程类的start()和run()
start()方法: 开始线程活动. 对每一个线程对象来说它只能被调用一次,它安排对象在一个另外的单独线程中调用run()方法,而非当前所处的线程,当该方法在同一个线程对象中被调用超过一次时,会引入R ...
- fiddler设置https抓包
代理端口设置:127.0.0.1:8888 https抓包设置 模拟post请求: http://xxx.xxxx.com/portal/login.htm Cookie: xxxx account= ...
- Python equivalent of D3.js
http://brandonrose.org/ Python equivalent of D3.js Ask Question Asked 7 years, 1 month ago Act ...
- PHP输出函数
1.print()输出 header('Content-Type:text/html;charset=utf-8'); print ("最近想学习PHP,大家推荐哪个学校好点?/n" ...
- Nginx 负载均衡算法
Nginx 负载均衡算法 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务,如果后端某台服务器死机,自动剔除故障系统,使用户访问不受影响. upstream tomcat_server { ...
- json去除value值的前后空格
/** * @Title: JsonStrTrim * @author : jsw * @date : 2012-12-7 * @time : 上午09:19:18 * @Description: 传 ...
- MySQL实战45讲学习笔记:第四十讲
一.本节概述 在上一篇文章中,我提到 MySQL 对自增主键锁做了优化,尽量在申请到自增 id 以后,就释放自增锁. 因此,insert 语句是一个很轻量的操作.不过,这个结论对于“普通的 inser ...
- ubuntu串口连接linux车机设备
一.用到的命令或者程序 1.dmesg命令 2.minicom软件 二.开搞 1.安装minicom sudo apt-get install minicom 2.查看串口信息 dmesg | gre ...
- win10 x64 VS2017 PJSIP 视频通话编译流程
win10 x64 VS2017 PJSIP 视频通话编译流程 1. 下载PJSIP源码 PJSIP源码下载地址:https://www.pjsip.org/ 2. 阅读一遍官方的文档 文档地址:ht ...