日期:2014-05-17 浏览次数:20828 次
就会抛出这个Log.d("mydebug","IOException error2");
public String download(String urlStr)
{
Log.d("mydebug","HttpDownloader ->download");
StringBuffer sb=new StringBuffer();
String line = null;
BufferedReader buffer=null;
HttpURLConnection urlConn=null;
try {
//创建一个URL对象
url=new URL(urlStr);
//创建一个Http对象
urlConn=(HttpURLConnection)url.openConnection();
}catch (MalformedURLException e1) {
Log.d("mydebug","MalformedURLException error");
e1.printStackTrace();
}catch(IOException e){
Log.d("mydebug","IOException error");
}
try{
//使用IO流读取数据
buffer=new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
while((line=buffer.readLine())!=null)
{
Log.d("mydebug","->"+line);
sb.append(line);
}
}catch(IOException e)
{
Log.d("mydebug","IOException error2");
}finally{
try{
buffer.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
Log.d("mydebug","HttpDownloader ->download2");
return sb.toString();
}