Database File Location for SQLite within MonoDroid

此生再无相见时 提交于 2019-12-13 02:48:24

问题


When using the following code to copy a SQLite database from an Assets folder , the output is being put in the following folder: "/data/data/AndroidTestDb.AndroidTestDb/files/AndroidTestDup.db"

Here is the code:

Stream myInput = Assets.Open(@"AndroidTest.db");

string outFileName=System.IO.Path.Combine(System.Environment.GetFolderPath 
(System.Environment.SpecialFolder.Personal), "AndroidTestDup.db");

Stream myOutput = new FileStream(outFileName, FileMode.OpenOrCreate);

And the desired folder +filename is :

"/data/data/AndroidTestDb.AndroidTestDb/databases/AndroidTestDup.db"

Thanks in Advance.


回答1:


There is no direct way, the closest I can think of is:

// someContext may be the current activity
String outFileName = someContext.getFilesDir().getParent().getAbsolutePath() + "/databases/AndroidTestDup.db";



回答2:


Use Context.GetDatabasePath to obtain the filesystem path for your database file:

// Assuming a Context subclass, e.g. an Activity
string dbPath = GetDatabasePath("AndroidTestDup.db").AbsolutePath;



回答3:


My idea to find out the sqlite database in monodroid is,

  • -First Install any android File Explorer application in your emulator.

  • -Then using the application just select any location you want to store your database.

  • -Then Use "adb push " command in adb. to copy your source
    database to a mobile location that
    you have selected.

  • -So now you know path of the database.

  • -Just use that path in your program.

Thank you...



来源:https://stackoverflow.com/questions/6319666/database-file-location-for-sqlite-within-monodroid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!