The program will choke at the place of (line = reader.readLine()) != null)
I try to use the following method to read pages from Internet, but sometime=
s the program will choke at the place of (line = reader.readLine()) != =
null), it tries to read content from internet again and again but still fai=
ls to get the line content, then the program stops at this position. How ca=
n I solve this problem, if it is possible to use another method the downloa=
d pages from internet or when the program is choked, if it is possible to s=
top it and restart the program again?
public String getHTMLResource(String htmlFile) throws IOException {
StringBuilder Content =new StringBuilder();
try {
String line = null;
URL url = new URL(htmlFile);
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamRea=
der(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
Content.append(line+"\n");
}
reader.close();
} catch (Exception e) {}
return Content.toString();
}