一般来讲,网络通信是先获取网页信息,在进行信息解析,下面是2种一般形式获取望去网页信息的写放,注意(2)捕获异常(2)inputsream要close
一、private String readStream(InputStream is)
{
InputStreamReader isr;
String result = "";
try
{
// 字节流转换为字符流
isr = new InputStreamReader(is, "utf-8");
// 字符流一buffer的形式读取
BufferedReader br = new BufferedReader(isr);
String line = "";
while((line = br.readLine()) != null)
{
result += line;
}
}
catch(UnsupportedEncodingException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
return result;
}
}
}