4

我正在尝试获取内部文件的最后修改日期,尽管我可以正确读取文件,但它总是返回 0。如果我做错了什么,请告诉我...

创建文件...

FileOutputStream Os = activity.openFileOutput("file1.jpg", Context.MODE_PRIVATE);
cachedImage.compress(CompressFormat.JPEG, 75, Os);
os.close();

正在读取文件...

长 mod_time = 0;
文件 file = new File("file1".jpg");
mod_time = file.lastModified();
FileInputStream Is = activity.openFileInput("file1.jpg");
cachedImage = BitmapFactory.decodeStream(Is);
Is.close() ;

mod_time 始终为零!!!!

4

1 回答 1

5

应该

File file = new File(activity.getFilesDir().getAbsolutePath() + "/file1.jpg");

这就是创建文件的地方。
简单检查:

File file = new File("file1.jpg");
Log.e("x", file.getAbsolutePath());
// /file1.jpg
Log.e("x", "" + file.exists());
// false
于 2010-07-30T20:28:49.547 回答