【Java】java 读写 json文件,java读写文件
package com.item1.hello;
import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
public class test1 {
// 测试json对象写入到文件
public static void testJsonWriteFile() throws IOException {
JSONArray ja = new JSONArray(); //json列表
JSONObject jo = new JSONObject(); //json字典
jo.put("filename", "test");
jo.put("value1", 123);
jo.put("value2", 12.34);
jo.put("value2", true);
ja.put(jo); //字典推入列表
File file = new File("");
FileUtils.write(file, ja.toString(), "utf-8", false);
}
public static void main(String[] args) throws IOException {
testJsonWriteFile();
}
}