23

我正在使用它来查看文件是否已经存在并获取其时间戳:

File file = new File(getResources().getString(R.string.file_name));

if (file.exists()) {
  Date lastModified = new Date(file.lastModified());
}

尽管我可以使用 Context.fileList() 方法看到这个文件确实存在,但上面的代码总是说它不存在。

如何获取文件的最后修改日期?

4

2 回答 2

13

我认为您的问题是file.exists()失败,修改日期的问题与此无关。

我敢说您使用的路径是您的应用程序的本地路径?使用时需要使用绝对路径File

于 2010-11-04T23:08:44.550 回答
1

使用它作为路径

如果您发送无效路径,那么您将始终得到 0 或 1970 的东西!(因为谷歌将开始日期设置为该日期:))

File file = new File(this.getFilesDir().getAbsolutePath() + "/file1.jpg");
于 2012-10-19T09:12:39.780 回答