When this code runs, it gets the content of a webpage.
I wanted to concatenate that entire string rather than printing it to the console but when I uncomment the two lines in the code below, System.out.println(inputLine);
prints nothing (but it worked with the line below commented) and the value fileText = null
,
where does this error come from?
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 fileText = "";
String inputLine;
while ((inputLine = in.readLine()) != null)
//fileText.concat(inputLine);
System.out.println(inputLine);
in.close();
//System.out.println(fileText);
}
}