返回要下载文件大小的方法

 
 
项目中用到的,忘记哪个网址找到的方法了,show:
 public int tryGetFileSize(URL url) {
        HttpURLConnection conn = null;
        try {
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("HEAD");
            conn.getInputStream();
            return conn.getContentLength();
        } catch (IOException e) {
            return -1;
        } finally {
            conn.disconnect();
        }
    }

你可能感兴趣的:(返回要下载文件大小的方法)