获取Android中网页的大小(以字节为单位)

时间:2013-12-02 08:35:58

标签: android

如何使用Android计算html(仅限html)网页的文件大小?

我试过了:

HttpGet request = new HttpGet(fullUrl);

HttpResponse response = new DefaultHttpClient().execute(request);
HttpEntity entity = response.getEntity();

InputStream input = entity.getContent();
int size = input.available();

但是available()总是返回零。

1 个答案:

答案 0 :(得分:3)

HttpResponse response = client.execute(httpPost);
String content = EntityUtils.toString(response.getEntity());
byte[] bytes = content.getBytes("UTF8");

<强>更新

URL url = new URL("http://server.com/file.mp3");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();