Java URL Value Check isUrlExists(String url)

Here you can find the source of isUrlExists(String url)

Description

is Url Exists

License

Open Source License

Declaration

public static boolean isUrlExists(String url) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static boolean isUrlExists(String url) {
        try {/*w  w  w.  j  a v a 2  s  .c  o  m*/
            URL urlObject = new URL(url);
            HttpURLConnection huc = (HttpURLConnection) urlObject
                    .openConnection();
            huc.setRequestMethod("HEAD");
            huc.connect();

            return huc.getResponseCode() == 200;
        } catch (IOException ignored) {
        }

        return false;
    }
}

Related

  1. isUrl(String value)
  2. isURLAccessible(String URL)
  3. isURLAvailable(String url, int timeout)
  4. isUrlAvailable(URL url, Proxy proxy)
  5. isUrlDownWithRetries(String url, long timeoutMs, long retryDelayMs)
  6. isURLExists(String URLName)
  7. isUrlInJar(URL url)
  8. isUrlResponding(String url)
  9. isUrlValid(final URL url)