Bug修复问题

采用下面的代码,访问网页:http://www.weather.com.cn/data/cityinfo/101010100.html,想读取下图中红框中的内容,但是抛出了IOException,通过各种测试介意确定现在的异常发生在程序中标黄色的地方,也就是reader.readLine()这一句,为什么??

Bug修复问题

读取网页的代码:

 public class HttpUtil {

     public static void sendHttpRequest(final String address,
final HttpCallBackListener listener) {
new Thread(new Runnable(){
@Override
public void run() {
HttpURLConnection connection = null ;
try {
URL url = new URL(address) ;
connection = (HttpURLConnection) url.openConnection() ;
connection.setRequestMethod("GET");
connection.setConnectTimeout(10000);
connection.setReadTimeout(10000);
InputStream in = connection.getInputStream() ;
BufferedReader reader = new BufferedReader(new InputStreamReader(in)) ;
StringBuilder response = new StringBuilder() ;
String line ; while((line = reader.readLine()) != null){
response.append(line) ;
}
if(listener != null){
//回调onFinish()方法
listener.onFinish(response.toString());
}
} catch (Exception e) {
if(listener != null){
listener.onError(e);
}
}finally{
if(connection != null){
connection.disconnect();
}
}
}
}).start() ;
} }
上一篇:Java设置PPT的扇形图,与内嵌Excel联动


下一篇:批量导出ppt中内嵌的图片