Android:数据库文件存储在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1105219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: Where are database files stored?
提问by Niko Gamulin
I created a SQLite database on Android device. The program can read/write to database so the database file has obviously been created. The SQLiteDatabase.mPath is set to
我在 Android 设备上创建了一个 SQLite 数据库。该程序可以读/写数据库,因此显然已经创建了数据库文件。SQLiteDatabase.mPath 设置为
db.mPath = "/data/data/dev.client.android/databases/clientDB.db"
but when I browse the directories on the device I can't locate the file clientDB.db. I looked inside data directory but it appears to be empty.
但是当我浏览设备上的目录时,我找不到文件 clientDB.db。我查看了数据目录,但它似乎是空的。
Does anyone know what could be wrong here?
有谁知道这里可能有什么问题?
采纳答案by CommonsWare
If you mean you visited /data
and found nothing in it, and you are examining an ordinary piece of Android hardware, that is expected. DDMS does not have permission to browse through /data
.
如果您的意思是您访问了其中/data
并没有发现任何内容,并且您正在检查一个普通的 Android 硬件,那么这是意料之中的。DDMS 无权浏览/data
.
However, at least if your app is compiled in debug mode, you can use the adb pull
command at the console to download your file directly.
但是,至少如果您的应用程序是在调试模式下编译的,您可以使用adb pull
控制台中的命令直接下载您的文件。
回答by browep
try getDatabasePath on ContextWrapper ( http://developer.android.com/reference/android/content/ContextWrapper.html). If you are in an Activity or Application class try:
在 ContextWrapper ( http://developer.android.com/reference/android/content/ContextWrapper.html)上尝试 getDatabasePath 。如果您在 Activity 或 Application 类中,请尝试:
File dbFile = getDatabasePath(MY_DB_NAME);
Log.i(dbFile.getAbsolutePath());
Just assuming its in /data/data/my.package.name/databases/
is bad as there is no guarantee the data has not been moved to the SD card or the device/OS has just decided on a different data directory.
假设它的输入/data/data/my.package.name/databases/
是坏的,因为不能保证数据没有移动到 SD 卡或设备/操作系统刚刚决定了不同的数据目录。
回答by kuester2000
In debug mode you can use adb shelland browse the directory content. In the shell you can call sqlite3 /data/data/dev.client.android/databases/clientDB.dbto analyse the DB.
在调试模式下,您可以使用adb shell并浏览目录内容。在 shell 中,您可以调用sqlite3 /data/data/dev.client.android/databases/clientDB.db来分析数据库。