Here you can find the source of getFileDateTime(URL url)
Parameter | Description |
---|---|
url | The URL of the file for which date and time will be returned. |
public static long getFileDateTime(URL url)
//package com.java2s; /*/*from ww w.java2s.c o m*/ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved. * * http://izpack.org/ * http://izpack.codehaus.org/ * * Copyright 2005 Marc Eppelmann * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.*; import java.net.URL; public class Main { /** * Gets file date and time. * * @param url The URL of the file for which date and time will be returned. * @return Returns long value which is the date and time of the file. If any error * occures returns -1 (=no file date and time available). */ public static long getFileDateTime(URL url) { if (url == null) { return -1; } String fileName = url.getFile(); if (fileName.charAt(0) == '/' || fileName.charAt(0) == '\\') { fileName = fileName.substring(1, fileName.length()); } try { File file = new File(fileName); // File name must be a file or a directory. if (!file.isDirectory() && !file.isFile()) { return -1; } return file.lastModified(); } catch (java.lang.Exception e) { // Trap all Exception based exceptions and return -1. return -1; } } }