您的位置:首页 > 理论基础 > 计算机网络

Android HttpURLConnection 获取下载文件大小

2018-01-30 15:22 567 查看
1、HttpURLConnection 获取下载文件大小

URL url = null;
String fileUrl = "http://XXXXX";
try {
url = new URL();
} catch (MalformedURLException e) {
e.printStackTrace();
}

HttpURLConnection urlcon = null;
try {
urlcon = (HttpURLConnection) url.openConnection();
int fileLength = urlcon.getContentLength();
log.d(TAG,"文件大小为:"+fileLength+"btye");
} catch (IOException e) {
e.printStackTrace();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息