Here you can find the source of isUrlValid(final URL url)
public static boolean isUrlValid(final URL url)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { /**/*from w w w.ja va 2 s .c om*/ * Quickly checks to see whether URL is reachable. */ public static boolean isUrlValid(final URL url) { final int timeout = 2000; // time, in milliseconds, used for open a link referenced by this URLConnection. if (url == null) return false; try { final HttpURLConnection huc = (HttpURLConnection) url.openConnection(); huc.setRequestMethod("HEAD"); huc.setConnectTimeout(timeout); // Using constant named final int responseCode = huc.getResponseCode(); return responseCode == HttpURLConnection.HTTP_OK; } catch (IOException ex) { return false; } } }