1

With to following code I'm receiving data trough API website feed. Whether someone can give me advice please which is the easiest way to run this code periodically on let say every 2 minutes (without clicking on run button manually)?

package Twister;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Base64;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


public class API {

   public static void main(String[] args) throws IOException {

       byte[] bytes = "username:password".getBytes("UTF-8");        
       String encoded = Base64.getEncoder().encodeToString(bytes);
       URL api = new URL("https://....");
       URLConnection apiConnection = api.openConnection();
       apiConnection.addRequestProperty("Authorization",
                "Basic " +   encoded );
       BufferedReader in = new BufferedReader(new InputStreamReader(apiConnection.getInputStream()));
       String storm;

        while ((storm = in.readLine()) != null)
        System.out.println(storm);

        in.close();
    }
} 
Pavle
  • 25
  • 4

0 Answers0