我用它来查看一个文件是否已经存在,并获取它的时间戳:
File file = new File(getResources().getString(R.string.file_name));
if (file.exists()) {
Date lastModified = new Date(file.lastModified());
}
尽管我可以使用Context.fileList()方法看到这个文件确实存在,但上面的代码总是说它不存在。
如何获取文件的上次修改日期?
发布于 2010-11-05 07:08:45
我认为你的问题是file.exists()
失败了,修改日期的问题与此无关。
我敢说你使用的路径对于你的应用程序来说是本地的?在使用File
时,您需要使用绝对路径。
发布于 2012-10-19 17:12:40
将此参数用于路径
如果你发送了无效的路径,那么你将总是得到0或者1970之类的东西!(因为Google将开始日期设置为该日期:)
File file = new File(this.getFilesDir().getAbsolutePath() + "/file1.jpg");
https://stackoverflow.com/questions/4102193
复制相似问题