如何使用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()总是返回零。
答案 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();