// retrieves url with HEAD. returns content length, // or -1 in case of error. public static long getURLSizeByHEAD(String url) { if (!url.contains("//")) url = "http://" + url; HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("HEAD"); conn.getInputStream(); return conn.getContentLength(); } catch (IOException e) { return -1; } finally { conn.disconnect(); } }