Here you can find the source of isURLAccessible(String URL)
Parameter | Description |
---|---|
URL | URL to find out whether is accessible |
public static boolean isURLAccessible(String URL)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007-2017 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v 1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * * Contributor://from ww w.j a v a 2s.c o m * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import java.net.HttpURLConnection; import java.net.URL; public class Main { /** * Finds out whether a URL returns HTTP OK or not. * * @param URL URL to find out whether is accessible * @return true if URL is accesible with HTTP OK exit code (200), false otherwise */ public static boolean isURLAccessible(String URL) { try { HttpURLConnection.setFollowRedirects(false); HttpURLConnection connection = (HttpURLConnection) new URL(URL) .openConnection(); connection.setRequestMethod("HEAD"); return (connection.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { return false; } } }