Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get last modified date from an assets file?

Bizarre question: is it possible to get the last modified date of a file in the assets folder, or would that be pointless and impossible?

I ask because I'm copying a read-only database out of there into the data folder on application start up, but would rather only perform the copy if the existing file is older than the one stored in the assets folder (or if the file doesn't exist).

If that's not possible, anyone know of a better convention? I can post that in a separate question if needed. TIA!

like image 850
Nathan Fig Avatar asked Mar 09 '11 15:03

Nathan Fig


1 Answers

How big/complex is the database? You might find it's easier and more flexible to use an instance of SQLiteOpenHelper to handle this since with one call to getReadableDatabase(), it will create if necessary the database, and call your onUpgrade to upgrade the database for you.

All you have to do is provide an onCreate() to create the database, provide onUpgrade() to upgrade, and increment the database version (in onUpgrade()) when it changes and Android will handle creating and upgrading the database for you.

Alternatively, (and I haven't tried this), it looks like AssetManager.list() can provide you a list of paths to your assets, next, use File (String path) to get a File object for the database, and finally File.lastModified() to get the modified date.

like image 106
RivieraKid Avatar answered Sep 21 '22 17:09

RivieraKid