java怎么读取文件中的json格式文件

2024-11-18 03:43:49
推荐回答(2个)
回答(1):

String fullFileName = "E:/a.json";

File file = new File(fullFileName);
Scanner scanner = null;
StringBuilder buffer = new StringBuilder();
try {
scanner = new Scanner(file, "utf-8");
while (scanner.hasNextLine()) {
buffer.append(scanner.nextLine());
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block

} finally {
if (scanner != null) {
scanner.close();
}
}

System.out.println(buffer.toString());

这是读取文件的方法,至于解析json,则你自己弄吧

回答(2):

有很多工具类的 json-lib.jar