Get size in bytes of webpage in Android

前端 未结 1 1820
广开言路
广开言路 2021-01-25 23:39

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 r         


        
相关标签:
1条回答
  • 2021-01-26 00:23
    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();
    
    0 讨论(0)
提交回复
热议问题