Java FileWriter Write saveToJson(Object object, String file)

Here you can find the source of saveToJson(Object object, String file)

Description

save To Json

License

Open Source License

Declaration

public static void saveToJson(Object object, String file) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.FileWriter;
import java.io.IOException;

import java.io.Writer;

public class Main {
    public static void saveToJson(Object object, String file) {
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        try {// w  w  w.  j  a  v  a  2 s  .  co  m
            Writer writer = new FileWriter(file);
            writer.write(gson.toJson(object));
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. saveToFile(String fileName, String resultStr)
  2. saveToFile(String fileName, String str)
  3. saveToFile(String location, File tempFile)
  4. saveToFile(String path, String line)
  5. saveToFile(String prefix, Reader input)
  6. saveToTempFile(File folder, String content, String fileType)
  7. saveTreeStructuredGroupList(ArrayList> treeStructuredGroupList, String filePath)
  8. saveTxt(String line, String filename, boolean isEndSave)
  9. saveTxtFile(String fileName, String content)