Here you can find the source of exists(URL url)
public static boolean exists(URL url)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; public class Main { public static boolean exists(String location) { try {/* w ww.j a v a2s . c om*/ return exists(newURL(location)); } catch (IOException e) { return false; } } public static boolean exists(URL url) { try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("HEAD"); return connection.getResponseCode() == HttpURLConnection.HTTP_OK; } catch (IOException e) { return false; } } public static URL newURL(String location) throws IOException { return newURI(location).toURL(); } public static URI newURI(String location) throws IOException { try { return URI.create(location); } catch (IllegalArgumentException e) { throw new IOException("malformed uri: " + location, e); } } }