从文本文件中读取内容

时间:2022-10-23 19:02:57

读取内容存为String

public static String parseJSONFile(String filename) throws JSONException, IOException {
   String content = new String(Files.readAllBytes(Paths.get(filename)))
   return content
}

读取内容存为JSONObject

public static JSONObject parseJSONFile2(String filename) throws JSONException, IOException {
   String content = new String(Files.readAllBytes(Paths.get(filename)))
   return new JSONObject(content)
}