在不同目录中找到SQLite数据库 [英] SQLite Database found in different directory

查看:72
本文介绍了在不同目录中找到SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常SQLite数据库位于 /data/data/PACKAGE-NAME/databases/DBNAME 中,但是我在 /data/user中找到了数据库一台设备中的/0/PACKAGE-NAME/databases/DBNAME 路径.

那么,为什么在单个设备中发生这种情况?

谢谢.

解决方案

您应该以编程方式获取数据库 file 路径,而不要使用硬编码方式.有关

如果要获取数据库文件夹路径,请使用如下所示的 getParent():

 字符串databaseFolderPath = context.getDatabasePath(dbname).getParent(); 

Generally SQLite database is locate in /data/data/PACKAGE-NAME/databases/DBNAME but I found database in /data/user/0/PACKAGE-NAME/databases/DBNAME path in one device.

So, why this happened in single device?

Thanks.

解决方案

You should programatically get the database file path rather than use a hardcoded manner. See API doc for getDatabasePath ; E.g.

// for `Activity`, `Service`. Otherwise simply get the context.
Context context = this;
String dbname = "dummy.db";
String dbpath = context.getDatabasePath(dbname).getPath();
Log.d("MY_TAG", dbpath);

If you want to get the database folder path, use getParent() like below:

String databaseFolderPath = context.getDatabasePath(dbname).getParent();

这篇关于在不同目录中找到SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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