android 网络下载获取文件大小

HttpURLConnection conn = (HttpURLConnection) url.openConnection();//建立连接
conn.setConnectTimeout(6*1000);
 conn.setRequestMethod("GET");
 conn.setRequestProperty("Accept-Language", "zh-CN");
 conn.setRequestProperty("Referer", downloadUrl); 
 conn.setRequestProperty("Charset", "UTF-8");
 conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
 conn.connect();
 if (conn.getResponseCode()==200) {
         this.fileSize = conn.getContentLength();
         if (this.fileSize <= 0) throw new RuntimeException("1无法获知文件大小 ");        


fileSize就是获得的网络文件大小

你可能感兴趣的:(android零碎知识点)