I'm creating files in my Android application using:
FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
fos.write(data);
fos.flush();
fos.close();
Then later I'm trying to do some cleanup, so I'm comparing the last modified date to some threshold value, but the comparison is showing that the file's last modified date is tomorrow sometime. Keep in mind, when I say tomorrow, that is relative to today (the file modification date)... whichever day this may be that you're reading this.
So basically, if I create the file today, and check the file's last modification date, it says it was last modified tomorrow.
Is this something Java is doing, or Android, or something I'm doing?
What does your test device/emulator show the current date and time as? It sounds like they're just set incorrectly.
Is the time zone on the device set to something other than your local time for instance?
I work on the similar problem (lastModified date is changed sometimes without touching to the file) but not find a workaround.
I create a test for create file, store value returned by lastModified function and check this value again after some actions to the phone (my device is Galaxy S
).
I found that lastModified uses internal cache while work and this cache can be cleared by enabling/disabling USB
mode (if a file is on SDCard
). I think also that this Cache
is cleared automatically after some interval. If cache has been cleared then the function read real value stored in the filesystem.
If you change the timezone on the device and clear the cache
then lastModified function will return another time (the difference depends on the new timezone, for example, if you change from GMT+3 to GMT+4 then the difference is 1 hour).
This problem is 100% reproducible.
Assuming that you are using java.io.File.lastModified()
, to get the last-modified timestamp, you are getting the number of milliseconds since 00:00:00 GMT, January 1, 1970. The timestamp is implicitly GMT/UTC based.
You should check other files on your phone that may be modified and created using FileOutputStream (possibly your photos). If they too have a modified date set to tomorrow, then I suggest you file a bug report to the manufacturers of your phone.
I assume it's a bug related to the phone because you said that this does not happen on your Nexus One.