Java Utililty Methods URL Exist

List of utility methods to do URL Exist

Description

The list of methods to do URL Exist are organized into topic(s).

Method

booleanexists(String fileorUrl)
exists
if (isUrl(fileorUrl)) {
    if (fileorUrl.startsWith("http")) {
        return existsHttp(fileorUrl);
    } else {
        try {
            URL url = new URL(fileorUrl);
            try {
                URLConnection uc = url.openConnection();
...
booleanexists(String url)
exists
try {
    return exists(new URL(url));
} catch (Exception e) {
    return false;
booleanexists(URL url)
exists
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("HEAD");
huc.connect();
return (huc.getResponseCode() == HttpURLConnection.HTTP_OK);
booleanexists(URL url)
exists
if ("http".equals(url.getProtocol())) {
    HttpURLConnection cnx = (HttpURLConnection) url.openConnection();
    return (HttpURLConnection.HTTP_OK == cnx.getResponseCode());
} else if ("file".equals(url.getProtocol())) {
    File f = new File(url.getPath());
    return f.exists();
throw new UnsupportedOperationException("only 'http' and 'file' protocol supported :" + url.getProtocol());
...
booleanexists(URL url)
exists
try {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("HEAD");
    return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
} catch (IOException e) {
    return false;
booleanexistsHttp(String URLName)
exists Http
try {
    HttpURLConnection.setFollowRedirects(false);
    HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
    con.setRequestMethod("HEAD");
    con.setConnectTimeout(10000);
    int code = con.getResponseCode();
    boolean ex = (code == HttpURLConnection.HTTP_OK);
    p("Exists url " + URLName + ", code: " + code + "= " + ex);
...
booleanexistsURL(String url)
Check if the specified URL exists.
try {
    HttpURLConnection.setFollowRedirects(true);
    HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    connection.setRequestMethod("HEAD");
    return (connection.getResponseCode() == HttpURLConnection.HTTP_OK
            || connection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT);
} catch (Exception e) {
    System.out.println("Error accessing: " + url);
...
booleanexistsURL_bak(String url)
Check if the specified URL exists.
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection conn = null;
boolean SUCCESS = false;
try {
    conn = (HttpURLConnection) new URL(url).openConnection();
    conn.connect();
    DataInputStream ins = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
    ins.close();
...