import java.io.FileWriter;
      import org.json.simple.JSONArray;
      import org.json.simple.JSONObject;
      
      try{
        JSONObject myJsonObject = new JSONObject(); 
        FileWriter file = new FileWriter("/path/to/file/to/write.json");
        myJsonObject.put("key", "value");
        file.write(myJsonObject.toJSONString()); 
        file.flush();
      } catch (IOException e) {
        e.printStackTrace();
      }
      Java language logo

      Write JSON object in a file

      json
      write
      file
      Java Public Recipes

      Write a JSON object directly in a file

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.