Here you can find the source of getContentLength(URL url)
public static long getContentLength(URL url) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.URL; import java.net.URLConnection; public class Main { public static long getContentLength(URL url) throws IOException { URLConnection conn = url.openConnection(); Long contentLength = conn.getContentLengthLong(); if (contentLength != null && contentLength >= 0) { return contentLength; }/*w ww.ja va 2 s. c om*/ String contentLengthValue = conn.getHeaderField("content-length"); if (contentLengthValue != null) { return Long.valueOf(contentLengthValue); } return -1; } }