Java URL Exist existsURL_bak(String url)

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

Description

Check if the specified URL exists.

License

Open Source License

Parameter

Parameter Description
url the URL to check

Return

true if the URL exists

Declaration

@Deprecated
public static boolean existsURL_bak(String url) 

Method Source Code

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

import java.io.*;
import java.net.*;

public class Main {
    /**//from  w  w w  .j a  v  a 2  s. c  o m
     * Check if the specified URL exists.
     * @param url the URL to check
     * @return true if the URL exists
     */
    @Deprecated
    public static boolean existsURL_bak(String url) {
        HttpURLConnection.setFollowRedirects(false);
        HttpURLConnection conn = null;
        boolean SUCCESS = false;

        try {
            conn = (HttpURLConnection) new URL(url).openConnection();
            conn.connect();

            //Try to open the stream, if it doesn't exist it will cause an exception.
            DataInputStream ins = new DataInputStream(
                    new BufferedInputStream(conn.getInputStream()));
            ins.close();

            conn.disconnect();
            SUCCESS = true;
        } catch (FileNotFoundException e) {
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null)
                conn.disconnect();
        }

        return SUCCESS;
    }
}

Related

  1. exists(URL url)
  2. exists(URL url)
  3. exists(URL url)
  4. existsHttp(String URLName)
  5. existsURL(String url)