读取resource下文件
ArrayList<PatrolOper> patrolOpers = new ArrayList<>(); String jsonData = null;
File jsonFile = null;
try {
jsonFile = ResourceUtils.getFile("classpath:jsonRequest.json");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
jsonData = FileUtils.readFileToString(jsonFile,"UTF-8");
} catch (IOException e) {
e.printStackTrace();
} Gson gson = new Gson();
PatrolTaskOperRequest bean = gson.fromJson(jsonData, PatrolTaskOperRequest.class); 主要在于,加载了好几次,都发现class下没json文件,后来发现,maven 对resource有过滤。
<!--配置Maven 对resource文件 过滤 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.json</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
读取resource下文件的更多相关文章
- SpringBoot读取Resource下文件的几种方式
https://www.jianshu.com/p/7d7e5e4e8ae3 最近在项目中涉及到Excle的导入功能,通常是我们定义完模板供用户下载,用户按照模板填写完后上传:这里模板位置resour ...
- SpringBoot读取Resource下文件的几种方式(十五)
需求:提供接口下载resources目录下的模板文件,(或者读取resources下的文件)给后续批量导入数据提供模板文件. 方式一:ClassPathResource //获取模板文件:注意此处需要 ...
- Spring Boot 读取 resource 下文件
支持linux下读取 import org.springframework.core.io.ClassPathResource; public byte[] getCertStream(String ...
- SpringBoot读取Linux服务器某路径下文件\读取项目Resource下文件
// SpringBoot读取Linux服务器某路径下文件 public String messageToRouted() { File file = null; try { file = Resou ...
- SpringBoot项目构建成jar运行后,如何正确读取resource下的文件
SpringBoot项目构建成jar运行后,如何正确读取resource下的文件 不管你使用的是SpringBoot 1.x还是SpringBoot2.x,在开Dev环境中使用eclipse.IEAD ...
- maven工程读取resource下配置文件
maven工程读取resource下配置文件 在maven工程中,我们会将配置文件放到,src/main/resources 下面,例如 我们需要确认resource 下的文件 编译之后存放的位置 ...
- Maven项目读取resources下文件的路径问题(getClassLoader的作用)
读取resources下文件的方法 网上有问答如下:问: new FileInputStream("src/main/resources/all.properties") new ...
- 微信退款SpringBoot读取resource下的证书
微信支付退款接口,需要证书双向验证,测试的时候证书暂时放在resource下,上图 起初MyConfig中我是这样,在本机IDE中运行没有问题 但到Linux服务器的docker中运行就IO异常了,查 ...
- Spring项目读取resource下的文件
目录 一.前提条件 二.使用ClassPathResource类读取 2.1.Controller.service中使用ClassPathResource 2.2.单元测试使用ClassPathRes ...
随机推荐
- 每天一个linux命令:【转载】tail命令
tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...
- 在编写异步方法时,使用 ConfigureAwait(false) 避免使用者死锁
我在 使用 Task.Wait()?立刻死锁(deadlock) 一文中站在类库使用者的角度看 async/await 代码的死锁问题:而本文将站在类库设计者的角度来看死锁问题. 阅读本文,我们将知道 ...
- Sprint第一个冲刺(第八天)
一.Sprint介绍 完善点餐界面,点击进行跳转. 实验截图: 任务进度: 二.Sprint周期 看板: 燃尽图:
- vue-router教程一(安装篇)
Installation安装 #直接下载/cdn https://unpkg.com/vue-router/dist/vue-router.js Unpkg.com提供基于NPM的CDN链接.上述链接 ...
- 1G1核1M选择 Centos 32位 还是 Centos 64位?
前几天有个疑惑,现有一台云主机是 1G1核1M使用 Centos 64位会不有点浪费. 还专门发信息询问老大 Karson,老大说现 FastAdmin 都是三个1,也是 64 位的. 看 FastA ...
- Linux环境安装配置Swftools
系统:CentOS6.5的64位版本 这里有一位仁兄的几个错误处理办法,下面是swftools的安装配置步骤: 1.安装所需的库和组件.机器之前安装过了,主要安装的是下面几个组件.如果不安装会 ...
- 坑爹的AMH
坑爹的 AMH的配置文件在这里: nginx 配置文件1:/usr/local/nginx-generic-1.6/conf/nginx.conf nginx 配置文件2:/home/wwwroot/ ...
- 用js实现屏蔽F12、鼠标右击、鼠标左击
function window.onhelp(){return false} //屏蔽F1帮助 document.onkeydown = function(){ if(window.event &am ...
- jq form表单自动赋值
(function ($) { $.fn.extend({ initForm: function (options) { //默认参数 var defaults = { formdata: " ...
- struts2学习(7)值栈简介与OGNL引入
一.值栈简介: 二.OGNL引入: com.cy.action.HelloAction.java: package com.cy.action; import java.util.Map; impor ...