Here you can find the source of getFilesizeFromUrl(String urlString)
public static int getFilesizeFromUrl(String urlString) throws IllegalStateException, IOException
//package com.java2s; /***************************************************************************** * This file is part of the Prolog Development Tool (PDT) * //from w ww. j a v a 2 s . c o m * Author: Andreas Becker * WWW: http://sewiki.iai.uni-bonn.de/research/pdt/start * Mail: pdt@lists.iai.uni-bonn.de * Copyright (C): 2012, CS Dept. III, University of Bonn * * All rights reserved. This program is made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * ****************************************************************************/ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static int getFilesizeFromUrl(String urlString) throws IllegalStateException, IOException { URL url = new URL(urlString.replace(" ", "%20")); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.connect(); int responseCode = conn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { return conn.getContentLength(); } else { throw new IllegalStateException("HTTP response: " + responseCode); } } }