Here you can find the source of getFileSize(URL url)
Parameter | Description |
---|---|
url | the url of the file |
public static int getFileSize(URL url)
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.HttpURLConnection; import java.net.URL; public class Main { /**/*from www.j a v a 2 s . co m*/ * Returns the size of the file located at the given URL. * * @param url the url of the file * * @return the size of the file */ public static int getFileSize(URL url) { HttpURLConnection conn = null; try { conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("HEAD"); conn.getInputStream(); return conn.getContentLength(); } catch (IOException e) { return -1; } finally { conn.disconnect(); } } }