是否有可能获得最后修改日期从资产的文件? [英] Is it possible to get last modified date from an assets file?

查看:136
本文介绍了是否有可能获得最后修改日期从资产的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的问题:是否有可能得到的资源文件夹中的文件的最后修改日期,或会认为是毫无意义的,也是不可能?

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).

如果这是不可能的,任何人都知道一个更好的公约?如果需要的话我可以张贴在一个单独的问题。 TIA!

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

推荐答案

如何大/复杂的是数据库?您可能会发现它更容易和更灵活地使用 <$ C $的一个实例C> SQLiteOpenHelper 同一个呼叫处理这一点,因为到<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getReadableDatabase%28%29\"相对=nofollow> getReadableDatabase() ,它会在必要的数据库中创建,并调用你的<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade%28android.database.sqlite.SQLiteDatabase%2c%20int%2c%20int%29\"相对=nofollow> onUpgrade 升级数据库给你。

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.

所有你需要做的是提供一个<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onCreate%28android.database.sqlite.SQLiteDatabase%29\"相对=nofollow> 的onCreate() 来创建数据库,提供<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade%28android.database.sqlite.SQLiteDatabase%2c%20int%2c%20int%29\"相对=nofollow> onUpgrade() 进行升级,并增加数据库版本(在<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade%28android.database.sqlite.SQLiteDatabase%2c%20int%2c%20int%29\"相对=nofollow> onUpgrade() ),当它改变和Android将负责创建和升级数据库给你。

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.

另外,(我没有试过),它看起来像<一个href=\"http://developer.android.com/reference/android/content/res/AssetManager.html#list%28java.lang.String%29\"相对=nofollow> AssetManager.list() 可以为您提供的路径列表,以你的资产,然后,使用的 文件(字符串路径) 以获取数据库中的文件对象,最后的 File.lastModified() 得到修改日期。

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.

这篇关于是否有可能获得最后修改日期从资产的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆