Here you can find the source of writeJsonToFile(Path jsonPath, String jsonContent)
public static void writeJsonToFile(Path jsonPath, String jsonContent)
//package com.java2s; //License from project: Apache License import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; public class Main { public static void writeJsonToFile(Path jsonPath, String jsonContent) { BufferedWriter jsonWriter = null; try {// w w w. ja v a 2s .co m jsonWriter = Files.newBufferedWriter(jsonPath, Charset.forName("utf-8")); jsonWriter.write(jsonContent, 0, jsonContent.length()); jsonWriter.flush(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { if (jsonWriter != null) { try { jsonWriter.close(); } catch (IOException e) { e.printStackTrace(); } } } } }