5

I have found in this site many questions asking how to open a database file located in the assets folder. Always the main point of the - correct - answer is the same: databases located in assets cannot be opened since such folder (as the entire content of the APK) is read only. Therefore the database file need to be copied somewhere else before it can be used ( Ship an application with a database ).

However, what if the database file in fact does not have to be modified ?. In that case it does not matter the restriction that the assets folder is read only.

Then my questions is:

Is there a way to open a read only database in the assets folder without copying it first to another location ?

Community
  • 1
  • 1
Sergio
  • 8,532
  • 11
  • 52
  • 94

2 Answers2

0

Use OPEN_READONLY flag e.g.

SQLiteDatabase.openDatabase(myPath,null,OPEN_READONLY);

You can find more flags here

And I think you have to copy the database to somewhere else first to be able to open it.

Community
  • 1
  • 1
C.d.
  • 9,932
  • 6
  • 41
  • 51
0

You'll need to copy it to the data folder, then read from there.

BlackDragonBE
  • 264
  • 1
  • 5
  • 1
    so there is NO WAY to read a database from the assets folder even if I am not affected by the restriction that this folder is read only (given that the DB does not need to be modified) ? – Sergio Jan 18 '12 at 18:15