在Android的网页的字节大小获取 [英] Get size in bytes of webpage in Android
本文介绍了在Android的网页的字节大小获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何计算一个HTML(只包含HTML)网页,随着Android的文件的大小?
我试过这样:
HTTPGET请求=新HTTPGET(fullUrl);HTT presponse响应=新DefaultHttpClient()执行(要求)。
HttpEntity实体= response.getEntity();输入的InputStream = entity.getContent();
INT大小= input.available();
但可用的()总是返回零。
解决方案
的Htt presponse响应= client.execute(httpPost);
字符串内容= EntityUtils.toString(response.getEntity());
字节[]字节= content.getBytes(UTF8);
更新
网址URL =新的URL(http://server.com/file.mp3);
URLConnection的的URLConnection = url.openConnection();
urlConnection.connect();
INT FILE_SIZE = urlConnection.getContentLength();
How can I calculate the file size of an html (just the html) web page with Android?
I tried this:
HttpGet request = new HttpGet(fullUrl);
HttpResponse response = new DefaultHttpClient().execute(request);
HttpEntity entity = response.getEntity();
InputStream input = entity.getContent();
int size = input.available();
But available() is always returning zero.
解决方案
HttpResponse response = client.execute(httpPost);
String content = EntityUtils.toString(response.getEntity());
byte[] bytes = content.getBytes("UTF8");
UPDATE
URL url = new URL("http://server.com/file.mp3");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();
这篇关于在Android的网页的字节大小获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文