how to write json string to file in java

htt‮p‬s://www.lautturi.com
how to write json string to file in java
/**
 * @author lautturi.com
 * Java example: write a JSON file in java
 */

import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		String data = "{\"age\":22,\"name\":\"Alice\"}";// data is a JSON string
		try (FileWriter file = new FileWriter("fileName.json")) {
			file.write(data);
			file.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
Created Time:2017-09-16 20:18:09  Author:lautturi