【问题标题】:Getting lastModified date for item in Asset folder?获取资产文件夹中项目的最后修改日期?
【发布时间】:2014-12-31 21:39:55
【问题描述】:

我的目标很简单:我的资产文件夹中有一个 zip 文件,并希望获得它的最后修改日期。

我可以通过 Assetmanager 访问该文件并从中创建一个文件,但修改日期是该文件被写入的时刻

    AssetManager manager;
    File checkFile = new File(source + "/" + "test.zip");

    try
    {
        InputStream stream = manager.open(fileToCheck);
        int size = stream.available();
        byte[] buffer = new byte[size];
        stream.read(buffer);
        stream.close();

        FileOutputStream fos = new FileOutputStream(checkFile);
        fos.write(buffer);
        fos.close();
    }
    catch(IOException ioExc)
    {
        //stuff
    }

        long lastMod = checkFile.lastModified();

        Date lastMod = new Date(lastMod ); //This is returning the current time, 
                                           //NOT the modified date of the file

谁能想到我可以访问资产文件夹中文件的实际最后修改日期的方法?任何帮助将不胜感激!

【问题讨论】:

    标签: android android-file android-assets


    【解决方案1】:

    最简单的方法是您可以将上次修改日期包含在该 zip 文件中(例如 lastmod.txt)。然后您可以解压缩并读取该文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 2021-12-07
      • 2019-02-26
      • 2011-11-02
      • 2010-09-17
      • 1970-01-01
      相关资源
      最近更新 更多