7 Sept 2012

check if a file exists at url in java


                                             
final URL url = new URL("http://some.where/file.html");
url.openConnection().getResponseCode();

try {
    final URL url = new URL("http://your/url");
    HttpURLConnection huc = (HttpURLConnection) url.openConnection();
    int responseCode = huc.getResponseCode();
    // Handle response code here...
} catch (UnknownHostException uhe) {
    // Handle exceptions as necessary
} catch (FileNotFoundException fnfe) {
    // Handle exceptions as necessary
} catch (Exception e) {
    // Handle exceptions as necessary
}

0 comments:

Post a Comment