读取json文件
public DocAndView gZipTest() throws Exception{
String filePath = "D:\\WeChat Files\\WeChat Files\\wxid_txqcr4gdjmvs21\\FileStorage\\File\\2022-10\\svg.txt";
String s = JarToPom.readJsonFile(filePath);
Document document = JsonUtil.json2doc(s);
return ViewUtil.getJsonView(document);
}
public static String readJsonFile(String fileName) {
String jsonStr = "";
try {
File jsonFile = new File(fileName);
FileReader fileReader = new FileReader(jsonFile);
Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"GB2312");
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 (IOException e) {
e.printStackTrace();
return null;
}
}