Green Green - 2 months ago 8
Java Question

Not able to read web page content

I am trying to read a web page content using below code. But it do not print the web content as is expected. There is no error seen on IDE. And there is no exception. Proxy is also not set. Could anyone guide why it might not be working

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

public class URLReader {
public static void main(String[] args) throws Exception {

URL oracle = new URL("http://www.oracle.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));

String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}


The control do not go inside while loop as debugged. But in buffer reader obj , there is a java object seen

Answer

The URL http://www.oracle.com/ is not an HTTPS URL, so you won't see any output when attempting to print the website's contents. Try running your program with this URL instead: https://www.oracle.com/