Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

Android: Where are database files stored?

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

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.

Does anyone know what could be wrong here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try getDatabasePath on ContextWrapper ( http://developer.android.com/reference/android/content/ContextWrapper.html ). If you are in an Activity or Application class try:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...