0

我想查询服务器以查看日期是否与我之前下载的手机上的日期不同。如果我已经拥有它,我想避免再次不必要地下载图像。寻找一种无需再次下载图像即可获取远程 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());
4

1 回答 1

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  ????
于 2012-06-13T15:40:52.860 回答