Java Path File Content writeJsonToFile(Path jsonPath, String jsonContent)

Here you can find the source of writeJsonToFile(Path jsonPath, String jsonContent)

Description

write Json To File

License

Apache License

Declaration

public static void writeJsonToFile(Path jsonPath, String jsonContent) 

Method Source Code

//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();
                }
            }
        }
    }
}

Related

  1. writeFile(Path path, String contents)
  2. writeFile(String path, String content)
  3. writeFile(String path, String content)
  4. writeFile(String path, String contents)
  5. writeFileContents(Path to, byte[] contents)
  6. writeLines(Path base, String file, String[] content)
  7. writeString(String content, Path path)
  8. writeStringToFile(String content, Path targetPath)
  9. writeToBinaryFile(String filePath, byte[] binaryContent)