Here you can find the source of isURLAvailable(String url, int timeout)
public static boolean isURLAvailable(String url, int timeout)
//package com.java2s; //License from project: Apache License import java.net.*; public class Main { public static boolean isURLAvailable(String url, int timeout) { try {/*from ww w. j a va 2s . c o m*/ return isURLAvailable(new URL(url), timeout); } catch (MalformedURLException e) { e.printStackTrace(); return false; } } public static boolean isURLAvailable(URL url, int timeout) { try { HttpURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) HttpURLConnection con = (HttpURLConnection) url .openConnection(); con.setRequestMethod("HEAD"); con.setConnectTimeout(timeout); return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { // e.printStackTrace(); return false; } } }