java读取json格式的文件
public static String getJson() {
String jsonStr = "";
try {
File file = new File(" ");
FileReader fileReader = new FileReader(file);
Reader reader = new InputStreamReader(new FileInputStream(file),"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) {
return null;
}
}
json转map
转载
https://www.cnblogs.com/heqiyoujing/p/9432153.html
本文介绍了如何使用Java通过FileReader和InputStreamReader从文件中读取JSON内容,并演示了如何将JSON字符串转化为Map,适合初学者理解基本操作。
1033

被折叠的 条评论
为什么被折叠?



