Obtenir le nombre d’octet d’un document web avec ‘getContentLength’

Author:

 url, date, url, java
Download

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
 
public class WebLength
{
  public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.exemple.com");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
 
    int taille_oct = conn.getContentLength();
    if (taille_oct>=0)
      System.out.println("Content-Length: " + taille_oct);
 }
}