Reputation: 11
Is it possible in SQLite to place the database files on a seperate folder inside of yourpackagename instead of yourpackagename/databases?
For example, I pass this string to the constructor of my SQLiteOpenHelper:
data/data/com.example.app/appbooks/App Book 1.db
Also tried doing this as the string, same result:
dbName = "data" + File.separator + "data" + File.separator + "com.example.app" + File.separator + "appbooks" + File.separator + dbName + ".db";
After that, I receive the an error in logcat at execution that the string above contains a path separator. I tried doing the usual slashes and replacing those slashes with File.separator, but the error still persists.
05-06 21:23:25.896: E/AndroidRuntime(5214): Caused by: java.lang.IllegalArgumentException: File data/data/com.example.app/appbooks/App Book 1.db contains a path separator
Upvotes: 1
Views: 1073
Reputation: 180260
Your databases must be in the directory returned by getDatabasePath()
.
If you really want to have an hierarchy of database file names, replace the path separator with any other character. (In Linux, file names can contain any character except /
.)
If you want to be particularly evil, use a backslash:
final String myFakeSeparator = "\\";
...
dbName = ... + File.separator + "appbooks" + myFakeSeparator + dbName + ".db";
Upvotes: 1