您的位置:首页 > 其它

练习 读取函数里的值

2015-01-16 10:22 92 查看
String getInput(){
String str="";
try
{
URL url = new URL("http://www.baidu.com/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(10000);
conn.setRequestMethod("GET");
conn.setRequestProperty("accept", "*/*");
String location = conn.getRequestProperty("location");
int resCode = conn.getResponseCode();
conn.connect();
InputStream stream = conn.getInputStream();
byte[] data=new byte[102400];
int length=stream.read(data);
str=new String(data,0,length);
conn.disconnect();
System.out.println(str);
stream.close();

}
catch(Exception ee)
{
System.out.print("ee:"+ee.getMessage());
}
return str; //返回str
}


  

调用方法 String a= getInput();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: