Here you can find the source of exists(URL url)
public static boolean exists(URL url) throws Exception
//package com.java2s; //License from project: LGPL import java.io.File; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static boolean exists(URL url) throws Exception { if ("http".equals(url.getProtocol())) { HttpURLConnection cnx = (HttpURLConnection) url.openConnection(); return (HttpURLConnection.HTTP_OK == cnx.getResponseCode()); } else if ("file".equals(url.getProtocol())) { File f = new File(url.getPath()); return f.exists(); }//ww w. jav a2 s .com throw new UnsupportedOperationException("only 'http' and 'file' protocol supported :" + url.getProtocol()); } }