Android网络操作(上传下载等)(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:49 点击:次
} finally {
//httpPost.abort();
}
return retrieveHttpEntity(httpEntity);
}
public static InputStream download(URL url) throws IOException {
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
return is;
}
public static byte[] downloadFileData(String surl) throws IOException {
URL url = new URL(surl);
URLConnection conn = url.openConnection();
// 获取长度
int length = (int) conn.getContentLength();
InputStream is = conn.getInputStream();
byte[] imgData = null;
if (length != -1) {
imgData = new byte[length];
byte[] temp = new byte[512];
int readLen = 0;
int destPos = 0;
while ((readLen = is.read(temp)) > 0) {
System.arraycopy(temp, 0, imgData, destPos, readLen);
destPos += readLen;
}
}
return imgData;
}
public static InputStream download(String url) throws IOException {
return download(new URL(url));
}
public static String httpPost(String url) throws ClientProtocolException, IOException {
return httpPost(url, new ArrayList<NameValuePair>());
}
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>