Path: csiph.com!usenet.pasdenom.info!news.chainon-marquant.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!198.186.194.247.MISMATCH!news-out.readnews.com!transit3.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: gearss8888@gmail.com Newsgroups: comp.lang.java.programmer Subject: The program will choke at the place of (line = reader.readLine()) != null) Date: Sat, 3 Mar 2012 18:03:13 -0800 (PST) Organization: http://groups.google.com Lines: 26 Message-ID: <29705069.30.1330826593295.JavaMail.geo-discussion-forums@ynbo9> NNTP-Posting-Host: 58.248.7.133 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1330826682 9567 127.0.0.1 (4 Mar 2012 02:04:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 4 Mar 2012 02:04:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=58.248.7.133; posting-account=K-H6MAoAAACf2uYihr0AgxpxKwbxYLCt User-Agent: G2/1.0 Xref: csiph.com comp.lang.java.programmer:12639 I try to use the following method to read pages from Internet, but sometime= s the program will choke at the place of (line =3D reader.readLine()) !=3D = 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 =3Dnew StringBuilder(); try { String line =3D null; URL url =3D new URL(htmlFile); URLConnection conn =3D url.openConnection(); BufferedReader reader =3D new BufferedReader(new InputStreamRea= der(conn.getInputStream())); while ((line =3D reader.readLine()) !=3D null) { Content.append(line+"\n"); } reader.close(); } catch (Exception e) {} return Content.toString(); }