Android 请问如何更改android 数据库的存储路径

Android 请问如何更改android 数据库的存储路径,第1张

These files will be ones that get deleted first when the device runs low on storage. There is no guarantee when these files will be deleted.

但是,最好不要依赖系统来管理,应该自己设定一个最大容量,当超出这个值时自己删除。

Context.getFilesDir(),Context.openFileOutput(String, int),Context.getFileStreamPath(String),Context.getDir(String, int)

/data/data/files

Android支持在SD卡上的应用私有目录,在Froyo版本后,通过getExternalFilesDir()可以获得具体路径。该路径依赖与应用的包名,如果你包为hello.file那么SD开上的应用私有目录为\mnt\sdcard\Android\data\hello.file\files\.

在使用SD卡目录时,需注意SD卡是否挂载,可通过Environment.getExternalStorageState()方法进行判断,如果返回值为Envirnment.MEDIA_MOUNTED表示SD卡处于挂载状态,可以放心使用。

getExternalCacheDir()和getCacheDir()比较

共同点:

files will be deleted when the application is uninstalled

不同点:

1、The platform does not monitor the space available in external storage, and thus will not automatically delete these files. Note that you should be managing the maximum space you will use for these anyway, just like with getCacheDir().

2、External files are not always available: they will disappear if the user mounts the external storage on a computer or removes it. See the APIs on Environment for information in the storage state.

3、There is no security enforced with these files. All applications can read and write files placed here.

存在res/raw/ 下面,然后程序启动的时候再把这个文件考到sd卡下,然后才能使用sqlite进行连接

追问:

sld=SQLiteDatabase.openDatabase

(

"/data/data/com.bn.fkdp/mydb", //数据库所在路径

null, //CursorFactory

SQLiteDatabase.OPEN_READWRITE|SQLiteDatabase.CREATE_IF_NECESSARY //读写、若不存在则创建

)

这是本人参考的一个程序中的数据库 本人想新建一个但是我在它的工程中怎么找不到"/data/data/com.bn.fkdp/mydb", 这个路径啊 请大侠指点一下

追答:

在DDMS里应该是可以找到那个路径的,如果是用模拟器运行的话。

在其他数据库上作开发,一般都使用工具来检查和处理数据库的内容,而不是仅仅使用数据库的

API。使用

Android

模拟器,有两种可供选择的方法来管理数据库。

首先,模拟器绑定了

sqlite3

控制台程序,可以使用

adb

shell

命令来调用他。只要你进入了模拟器的

shell,在数据库的路径执行

sqlite3

命令就可以了。数据库文件一般存放在:

/data/data/your.app.package/databases/your-db-name

如果你喜欢使用更友好的工具,你可以把数据库拷贝到你的开发机上,使用

SQLite-aware

客户端来 *** 作它。这样的话,你在一个数据库的拷贝上 *** 作,如果你想要你的修改能反映到设备上,你需要把数据库备份回去。

把数据库从设备上考出来,你可以使用

adb

pull

命令(或者在

IDE

上做相应 *** 作)。存储一个修改过的数据库到设备上,使用

adb

push

命令。

一个最方便的

SQLite

客户端是

FireFox

SQLite

Manager

扩展,它可以跨所有平台使用。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/6764028.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-28
下一篇2023-03-28

发表评论

登录后才能评论

评论列表(0条)

    保存