由以下代码读取一个网页:
try{
URL u=new URL("http://www.sohu.com");
URLConnection uc=u.openConnection();
InputStream raw=uc.getInputStream();
InputStream buffer=new BufferedInputStream(raw);
Reader r=new InputStreamReader(buffer);
int c;
while((c=r.read())!=-1)
{
System.out.print((char) c);
} //end while
}//end try
catch (IOException e){
System.err.println(e);
}// end catch
}// end main是不是有可能由于网速很慢,打开网页超时而进入异常处理。
若是这样,能否将超时时间设为无穷大,等到读完网页后再
继续往下运行!谢谢!
try{
URL u=new URL("http://www.sohu.com");
URLConnection uc=u.openConnection();
InputStream raw=uc.getInputStream();
InputStream buffer=new BufferedInputStream(raw);
Reader r=new InputStreamReader(buffer);
int c;
while((c=r.read())!=-1)
{
System.out.print((char) c);
} //end while
}//end try
catch (IOException e){
System.err.println(e);
}// end catch
}// end main是不是有可能由于网速很慢,打开网页超时而进入异常处理。
若是这样,能否将超时时间设为无穷大,等到读完网页后再
继续往下运行!谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货