1. json 출력

1
2
3
4
5
6
7
8
9
10
11
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", "아이언맨");
map.put("name", "어벤저스");

Gson gson = new Gson();

String path = "C:\\test\\test1.json";

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"));
writer.write(gson.toJson(map, Map.class));
writer.close();

2. json 입력

1
2
3
4
5
6
7
8
9
Gson gson = new Gson();

String path = "C:\\test\\test1.json";

BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));

Map<String, Object> map = gson.fromJson(reader, Map.class);

System.out.println(map);

json의 입력은 Gson을 사용하면 간편하게 처리할수 있다