//读取json文件
public static String readJsonFile(String name) {
String jsonStr = "";
try {
File fileName = ResourceUtils.getFile(name);
FileReader fileReader=new FileReader(fileName);
Reader reader = new InputStreamReader(new FileInputStream(fileName),"utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
return jsonStr;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
```
String canShuStr = ReadJsonFileUtils.readJsonFile("classpath:confJson/canShu.json");
JSONObject canShuJson = JSONObject.parseObject(canShuStr);
json文件的读取
最新推荐文章于 2024-01-24 20:00:00 发布