Java examples for Network:URL Download
get Remote File Size via URL
//package com.java2s; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static void main(String[] argv) throws Exception { String url = "java2s.com"; System.out.println(getRemoteFileSize(url)); }//from w w w . j a va 2 s . co m public static long getRemoteFileSize(String url) { long size = 0; try { HttpURLConnection conn = (HttpURLConnection) (new URL(url)) .openConnection(); size = conn.getContentLength(); conn.disconnect(); } catch (Exception e) { e.printStackTrace(); } return size; } }