Android: getting lastModified private file

I am trying to get the last modified date of the internal file, and it always returns me 0, although I could read the file correctly. Could you tell me if I am doing something wrong ...

Creating a file ...

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

Reading 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);
Close();

mod_time is always zero !!!!

+4
source share
1 answer

Must be

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

Where the file is being created.
Simple check:

 File file = new File("file1.jpg"); Log.e("x", file.getAbsolutePath()); // /file1.jpg Log.e("x", "" + file.exists()); // false 
+4
source

All Articles