Android HttpURLConnection 获取下载文件大小

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();
}

你可能感兴趣的:(安卓)