Android:如何从我想下载的图像的URL获取文件日期?

时间:2012-06-13 03:06:16

标签: android url date

我想查询服务器以查看日期是否与手机上的日期不同 我之前下载过的。如果我已经拥有它,我想不要再次下载图像了。寻找一种方法来获取远程URL文件的日期和时间,而无需再次下载图像。以下代码可以获取所有内容。

       File root = Environment.getExternalStorageDirectory();
   URL u = new URL(url);
   HttpURLConnection c = (HttpURLConnection) u.openConnection();
   c.setRequestMethod("GET");
   c.setDoOutput(true);
   c.connect();
   InputStream in = c.getInputStream();
   Drawable d = Drawable.createFromStream(in, "src name");
   printi("Content length",c.getContentLength());

1 个答案:

答案 0 :(得分:2)

   File root = Environment.getExternalStorageDirectory();
   URL u = new URL(url);
   HttpURLConnection c = (HttpURLConnection) u.openConnection();
   c.setRequestMethod("HEAD");

   c.connect();
   InputStream in = c.getInputStream();
   long dt=c.getLastModified();  //File Modified Date!!!
   printtime("File Time ",dt);
   c.disconnect();       //close connection  ????