Java URL Value Check isValidURL(String URL_String)

Here you can find the source of isValidURL(String URL_String)

Description

Opens up a connection with the given URL and returns true if the response code is 200 (success)

License

Open Source License

Parameter

Parameter Description
URL_String the URL to test

Return

Host reachability

Declaration

public static boolean isValidURL(String URL_String) 

Method Source Code

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

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    /**//from w  w  w .  ja v  a  2  s  .  c  o  m
     * Opens up a connection with the given URL and returns true if the response code is 200 (success)
     * @param URL_String the URL to test
     * @return Host reachability
     */
    public static boolean isValidURL(String URL_String) {
        try {
            URL url = new URL(URL_String);
            url.toURI();
        } catch (MalformedURLException e) {
            return false;
        } catch (URISyntaxException e) {
            return false;
        }
        return true;
    }
}

Related

  1. isValidURL(String link)
  2. isValidURL(String url)
  3. isValidURL(String url)
  4. isValidURL(String url)
  5. isValidUrl(String url)
  6. isValidURL(String urlStr)
  7. isValidURL(String urlStr)
  8. isValidURL(String urlString)
  9. isValidUrl(URI uri)