问题描述
如何获取文件属性(如日期),而无需下载文件,如果我有文件的URL
我必须实现更新检查器。为此我要比较两个文件的日期。一个是本地的,第二个是相同的文件,但在服务器上有最新的日期。我知道第二个文件的URL。
请给我一个和平的建议 - 如何检查第二个文件的日期而不下载它?
$ b
我曾经想过通过散列进行比较,但我需要检查服务器上的文件是否是最新版本?
url = new URL(inputFile);
URLConnection urlConnection = url.openConnection();
System.out.println(Date =+ new Date(urlConnection.getLastModified()));
System.out.println(Size =+ urlConnection.getContentLength());
} catch(MalformedURLException e1){
e1.printStackTrace(); // Todo改变catch语句的主体
} catch(IOException e1){
e1.printStackTrace(); // Todo改变catch语句的主体
}
具有日期,大小,名称的属性可以识别资源。 / p>
How to get file properties (e.g. date) without downloading file if I have URL of the file.
I have to implement updates checker. For this purpose I'm going to compare dates of two files. One is local, the second is the same file but with latest date on server. I know URL to the second file.
Please, give me a peace of advice - how to check date of the second file without downloading it?
I have thought about comparing via hash, but I need to check whether file on server is latest version or not?
To check the file date you can use this snippet of code
try {
URL url = new URL(inputFile);
URLConnection urlConnection = url.openConnection();
System.out.println("Date= "+new Date(urlConnection.getLastModified()));
System.out.println("Size= "+urlConnection.getContentLength());
} catch (MalformedURLException e1) {
e1.printStackTrace(); //Todo change body of catch statement.
} catch (IOException e1) {
e1.printStackTrace(); //Todo change body of catch statement.
}
with the attributes of date, size, name you can identify the resource.
这篇关于如何获得文件属性,而无需下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!