Get content length for a URL connection in Java
Description
The following code shows how to get content length for a URL connection.
Example
//from w ww.ja v a 2 s . co m
import java.net.URL;
import java.net.URLConnection;
public class Main {
public static void main(String args[]) throws Exception {
URL u = new URL("http://www.google.com");
URLConnection uc = u.openConnection();
System.out.println("Content-length: " + uc.getContentLength());
}
}
The code above generates the following result.