Добрый день. Есть такой кусочек программы, который делает запрос к VK API и в консоле выводится ответ ввиде json структуры.Кусок рабочий. Необходимо, сохранить в файл полученный ответ
package test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MAin {
public static void main(String[] args) {
String key = "7075966f7075966f7075966f577018909e770757075966f2dfd2579655817dfd28d3bfd";
String Vers = "5.103";
String url = "https://api.vk.com/method/photos.search?user_ids=210700286&fields=bdate&lat=55.879960&long=38.227373&count=1"
+ "&access_token=" + key+"&v="+Vers;
try {
URL obj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}catch(Exception e){}
}
}
ВЫВОД ПРОГРАММЫ
{"response":{"count":1884715,"items":[{"id":457255258,"album_id":-7,"owner_id":-165200868,"user_id":100,"sizes":[{"type":"m","url":"https:\/\/sun9-12.userapi.com\/c857720\/v857720134\/105a30\/FE61LF5dwl8.jpg","width":97,"height":130},{"type":"o","url":"https:\/\/sun9-63.userapi.com\/c857720\/v857720134\/105a34\/IJ_m-FQqc9c.jpg","width":130,"height":173},{"type":"p","url":"https:\/\/sun9-31.userapi.com\/c857720\/v857720134\/105a35\/sdr_IPxNbWY.jpg","width":200,"height":267},{"type":"q","url":"https:\/\/sun9-25.userapi.com\/c857720\/v857720134\/105a36\/YVHr-gP2N60.jpg","width":320,"height":427},{"type":"r","url":"https:\/\/sun9-62.userapi.com\/c857720\/v857720134\/105a37\/fF-dR54i-a0.jpg","width":510,"height":680},{"type":"s","url":"https:\/\/sun9-52.userapi.com\/c857720\/v857720134\/105a2f\/Hdd42ysZ4Gk.jpg","width":56,"height":75},{"type":"x","url":"https:\/\/sun9-42.userapi.com\/c857720\/v857720134\/105a31\/qU3dETFpYeI.jpg","width":453,"height":604},{"type":"y","url":"https:\/\/sun9-50.userapi.com\/c857720\/v857720134\/105a32\/oUHzyvLab4I.jpg","width":605,"height":807},{"type":"z","url":"https:\/\/sun9-63.userapi.com\/c857720\/v857720134\/105a33\/-Pl-Dw63RhY.jpg","width":780,"height":1040}],"text":"","date":1574847986,"lat":55.869231,"long":38.203026}]}}
Как реализовать сохранение в файл json, то что мне вывела консоль? Буду благодарен если мне поможете или допишите программу