Results 1 to 1 of 1
-
Check if a web page exists or not
The code snippet presented below shows how to check if a web page exists not not.
Java Code:public class URLUtils { public static void main(String s[]) { System.out.println(URLUtils.exists ("http://www.java-forums.org/howto.html")); System.out.println(URLUtils.exists ("http://www.java-forums.org/pagenotfound.html")); /* output : true false */ } public static boolean exists(String URLName){ try { HttpURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection(); con.setRequestMethod("HEAD"); return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { e.printStackTrace(); return false; } } }
Similar Threads
-
File fp = new File(filePath);fp.exists() does not yeild proper result
By ganeshp in forum Advanced JavaReplies: 2Last Post: 04-07-2009, 06:25 AM -
How to check whether file is exists or not
By Java Tip in forum java.ioReplies: 0Last Post: 04-05-2008, 10:13 AM -
Can someone check my code
By joz_12345 in forum Java 2DReplies: 7Last Post: 02-18-2008, 02:58 AM -
How an array can check that profile whether exists or not???
By hien_NU in forum New To JavaReplies: 1Last Post: 01-10-2008, 01:18 AM -
spell check
By kazitula in forum Java AppletsReplies: 2Last Post: 12-20-2007, 11:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks