views:

85

answers:

1

Hi Guys,

I am trying to get the last modified date of an internal file and it always returns me 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!!!!

+1  A: 

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
alex