The list of methods to do URL Exist are organized into topic(s).
boolean
exists(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();
...
boolean
exists(String url) exists
try {
return exists(new URL(url));
} catch (Exception e) {
return false;
boolean
exists(URL url) exists
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("HEAD");
huc.connect();
return (huc.getResponseCode() == HttpURLConnection.HTTP_OK);
boolean
exists(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());
...
boolean
exists(URL url) exists
try {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("HEAD");
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
} catch (IOException e) {
return false;
boolean
existsHttp(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);
...
boolean
existsURL(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);
...
boolean
existsURL_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();
...