Here you can find the source of write2Json(String json, String path, String name)
public static void write2Json(String json, String path, String name) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void write2Json(String json, String path, String name) throws IOException { File pathFile = new File(path); if (!pathFile.isDirectory()) { throw new FileNotFoundException(); }//from w w w . j a v a2s. c o m if (!pathFile.exists()) { pathFile.mkdirs(); } if (name == null) { name = getDefaultName(); } File file = new File(path + "/" + name); FileWriter writer = new FileWriter(file, true); if (file.length() == 0) { writer.append("["); } writer.append(json + ","); writer.close(); } private static String getDefaultName() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(new Date()) + ".json"; } }