Writing a JSON Object to File - Java JSON

Java examples for JSON:JSON Creation

Description

Writing a JSON Object to File

import java.io.FileWriter;

import javax.json.Json;
import javax.json.JsonObject;

public class Main {

  public static void main(String[] args) {
    JsonObject jsonObject = null;
    try (javax.json.JsonWriter jsonWriter = Json.createWriter(new FileWriter(
        "Book.json"))) {
      jsonWriter.writeObject(jsonObject);
    } catch (Exception ex) {
      System.out.println(ex);
    }

  }
}

Related Tutorials