Android: Getting lastModified of a private file
I am trying to get the last modified date of an internal file and it always returns m开发者_运维百科e 0 although I could read the file properly. Can you please let me know if I am doing anything wrong...
Creating a file...
FileOutputStream Os = activity.openFileOutput("file1.jpg", Context.MODE_PRIVATE);
cachedImage.compress(CompressFormat.JPEG, 75, Os); Os.close();Reading the file...
long mod_time = 0;
File file = new File("file1".jpg"); mod_time = file.lastModified(); FileInputStream Is = activity.openFileInput("file1.jpg"); cachedImage = BitmapFactory.decodeStream(Is); Is.close();mod_time is always zero!!!!
Should be
File file = new File(activity.getFilesDir().getAbsolutePath() + "/file1.jpg");
That's where the file is created.
Simple check:
File file = new File("file1.jpg");
Log.e("x", file.getAbsolutePath());
// /file1.jpg
Log.e("x", "" + file.exists());
// false
精彩评论