private Date getLastModifiedTime ( URL url ) { // see http://stackoverflow.com/questions/2416872/how-do-you-obtain-modified-date-from-a-remote-file-java Date date = null ; try { String lastModified = url . openConnection ( ) . getHeaderField ( "Last-Modified" ) ; logger . debug ( "Last modified date of server file ({}) is {}" , url . toString ( ) , lastModified ) ; if ( lastModified != null ) { try { date = new SimpleDateFormat ( "E, d MMM yyyy HH:mm:ss Z" , Locale . ENGLISH ) . parse ( lastModified ) ; } catch ( ParseException e ) { logger . warn ( "Could not parse last modified time from string '{}', no last modified time available for file {}" , lastModified , url . toString ( ) ) ; // this will return null } } } catch ( IOException e ) { logger . warn ( "Problems while retrieving last modified time for file {}" , url . toString ( ) ) ; } return date ; }
Get the last modified time of the file in given url by retrieveing the Last - Modified header . Note that this only works for http URLs