0

I want to print the values ​​in the url but I'm new can you help me? ......................................................

    import java.util.*; 
import java.io.*;
import java.net.*;

class Main {  
  public static void main (String[] args) { 
    System.setProperty("http.agent", "Chrome");
    try { 
      URL url = new URL("https://coderbyte.com/api/challenges/json/rest-get-simple");
      try {
        URLConnection connection = url.openConnection();
        InputStream inputStream = connection.getInputStream();
        
        System.out.println(inputStream);
      } catch (IOException ioEx) {
        System.out.println(ioEx);
      }
    } catch (MalformedURLException malEx) {
      System.out.println(malEx);
    }
  }   
}
1

1 Answer 1

0

try this

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

    public class UrlConnectionReader {
        public static void main(String[] args) throws MalformedURLException,             IOException {
    InputStream in = null;
    System.setProperty("http.agent", "Chrome");
    try {
         in = new URL("https://coderbyte.com/api/challenges/json/rest-get-simple").openStream();
        InputStreamReader inR = new InputStreamReader(in);
        BufferedReader buf = new BufferedReader(inR);
        String line;
        while ((line = buf.readLine()) != null) {
            System.out.println(line);
        }
    } finally {
        in.close();
    }
}

}

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much so how can i read array elements in url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.