JSONBuilder可以向文件中写入写入json字符串。如下面的例子:
public class Test { public static void main(String args[]) throws IOException { File f = new File("d:" + File.separator + "test.txt"); FileWriter fw = new FileWriter(f); JSONBuilder builder = new JSONBuilder(fw); builder.object(); builder.key("Json"); builder.value("Hello, World!"); builder.endObject(); fw.flush(); fw.close(); } }
输出结果为:{"Json":"Hello, World!"}
时间: 2024-11-06 07:22:54