I'm developing an application and I've run into two problems here:
How can I open an SQLite database which is stored in the assets folder? What path do I use to access the assets folder in my application? Here's what I have so far:
path = "file:///asset_folder/database.dat"; SQLiteDatabase db = null; db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
How can I copy a file to the internal memory (
/data/data/...
) during the installation of my application or during the first run? I want to copy a folder inside the assets folder into the internal memory during the first run.
Any suggestions would be greatly appreciated.
Copy database from assets folder to data/data/database folder of your application. Use Below code.
I was having the same problem, so I moved the db file to the res/raw folder, and accessed it like so:
Then I tried to move the file into the /data/data/com.mydomain.www/databases/ folder, but I would get an exception because the destination path didn't exist, so I did
File(destPath).getParentFile().mkdir();
From there, I called a copy db method to transfer the db to the destination.
InputStream is the db file, OutputStream is the FileOutputStream(destPath).
From this post i found this tutorial. It tells you how to deal with databases in your assets folder. That at least answers your first question. I'm not too sure about your second.