Search code examples
javaurlbluej

Open urls in BlueJ


is it possible to open urls in BlueJ. For example in PHP I can use the function file_get_contents()

Is there something equal in BlueJ?


Solution

  • You need to look at using a buffered reader and using the URL object in Java.

    It's basically something like this:

    URL url = new URL("http://myurl.com");
    URLConnection conn = url.openConnection();
    BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String input = "";
    while((input = reader.readLine())!=null) {
        System.out.println(input);
    }