---
title: "http获取文件大小"
author: "jguangyou"
date: "2012-09-21T10:03:03Z"
tags: []
categories: ["移动开发"]
slug: "http"
draft: false
lastmod: "2012-09-21T10:03:03Z"
id: 1682759
url: "https://deep-fish.iteye.com/blog/1682759"
---

URL url = new URL(downloadUrl);  
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();  
  conn.setConnectTimeout(5 * 1000);  
  conn.setRequestProperty("Accept-Language", Params.ACCEPT\_LANGUAGE);  
  conn.setRequestProperty("Charset", Params.ChARSET);  
  conn.setRequestMethod("GET");  
  conn.setRequestProperty("Connetion", "Keep-Alive");  
  // 文件大小  
  int fileSize = conn.getContentLength();