How to make a loop. Request vk api in java?

Good afternoon. There's a code that sends an API request to get photographs in a particular area, and saves the resulting json file.

String key = "7075966f7075966f7075966f577018909e770757075966f2dfd2579655817dfd28d3bfd";
 String Vers = "5.103";
 System.out.println("Latitude ");
 String LATITUDE =;
 System.out.println("Longitude ");
 String LONGITUDE =;
 System.out.println("Specify a search radius (e.g. 100 meters) = ");
 String radius =;
 String url = ""
 + "&lat=" + LATITUDE 
 + "&long=" + LONGITUDE
 + "&count=" + count
 + "&radius=" +radius 
 + "&access_token=" + key
 + "&v=" + Vers;
try {
 URL obj = new URL(url);
 HttpURLConnection connection = (HttpURLConnection) obj.openConnection();

 BufferedReader in = new BufferedReader(new an InputStreamReader(connection.getInputStream()));
 String inputLine;
 StringBuffer response = new StringBuffer();

 while ((inputLine = in.readLine()) != null) {
 try (FileWriter file = new FileWriter("response-vk.json")) {
}catch(Exception e){}


When you get such json response structure

Stitch count:5356 shows the number of photos in this my area. Since a single query, VK allows to 1,000 photos. I need to get all 5356 photos

But in VC is an option as offsetc (offset relative to the first found user to fetch a specific subset.)

Help get all of the photos(not just the first thousand that I receive at my request).Can't think of how to do it
April 3rd 20 at 18:27
1 answer
April 3rd 20 at 18:29
loop with integer remainder (count, 1000) +1
If I understand correctly, I need something to organize the reading I don't manually enter it. And make the loop? - monroe_Aufderh commented on April 3rd 20 at 18:32
get count of first response and use safely, it is still the first iteration of a request to do anyway. do not forget to check for null - Jadyn commented on April 3rd 20 at 18:35

Find more questions by tags JavaAPIVKontakte