Java URL Value Check isAValidURL(String url)

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

Description

is A Valid URL

License

Apache License

Declaration

public static boolean isAValidURL(String url) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static boolean isAValidURL(String url) {
        URL u = null;/*from   ww  w  .  ja v a 2 s  .  c  o  m*/
        HttpURLConnection huc = null;
        try {
            u = new URL(url);
            huc = (HttpURLConnection) u.openConnection();
            huc.setRequestMethod("HEAD");
            huc.connect();
            return (huc.getResponseCode() == HttpURLConnection.HTTP_OK);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (huc != null)
                huc.disconnect();
        }
        return false;
    }
}

Related

  1. invokePostUrl(String url, String encodedQueryString)
  2. invokeUrl(String url)
  3. is200(final String url)
  4. is404(URL url)
  5. isAddressReachable(String url, int timeout)
  6. isCompressed(HttpURLConnection connection)
  7. isEMailAddress(URL url)
  8. isFile(final URL url)
  9. isFile(final URL url)