springboot打成jar后无法读取根路径和文件

最近遇到一个问题,springboot项目打包成jar后用

ResourceUtils.getFile("classpath:properties/bankMap.json");
String result = FileUtils.readFileToString(jsonFile, "UTF-8");

无法读取resource下的文件,

后面改成

ClassPathResource resource = new ClassPathResource("properties/bankMap.json");
BufferedReader br = new BufferedReader(
		new InputStreamReader(
				new ClassPathResource("properties/bankMap.json").getStream()));
String result = "";
String line = null;
while ((line = br.readLine()) != null) {
	result += line;
}
br.close();

转换成String输出就可以了,踩坑了

你可能感兴趣的:(spring,boot,java)