springboot 读取resources路径下的json文件并转换为json。
@Resource
protected ResourceLoader resourceLoader;
private JSONObject _getConfJoFromJsonFile(){
try {
var resource = resourceLoader.getResource("classpath:conf.json");
String jsonStr = new String(resource.getInputStream().readAllBytes());
System.out.println(jsonStr);
return(JSONObject.parse(jsonStr));
}
catch (IOException ioException){
System.out.println(ioException.getMessage());
Asserts.fail(-1001,"读取conf.json出错。"+ioException.getMessage());
return JSONObject.of();
}
}
网友评论