通过注解读取文件
@Value("classpath:static/json/addTask.json")
Resource addTaskJson;
其他配置
前缀 | 例子 | 说明 |
---|---|---|
classpath: | classpath:com/myapp/config.xml | 从classpath中加载 |
file: | file:/data/config.xml | 作为 URL 从文件系统中加载 |
http: | http://myserver/logo.png | 作为 URL 加载 |
(none) | /data/config.xml | 根据 ApplicationContext 进行判断 |
摘自于Spring Framework参考手册
转化为 字符串 转化为 JSON 对象
String jsonStr = new String(IOUtils.readFully(addTaskJson.getInputStream(), -1,true));
JSONObject json = JSONObject.parseObject(jsonStr);
注意: 该方法需要 jdk1.8的环境
留言