I am trying to copy a ready made sqlite v3 database from my assets folder into the /databases folder of my app. But I get a java runtime exception.
private const string DB_PATH = "/data/com.MyApp/databases/dbname";
public SQLiteDatabase GetDataBase()
{
SQLiteDatabase db = null;
try
{
db = SQLiteDatabase.OpenDatabase(DB_PATH, null, SQLiteDatabase.OPEN_READONLY);
}
catch
{
this.GetReadableDatabase();
InputStream inStream = _appContext.GetAssets().Open("HadithCompanion.bukhari");
Helper.CreateFileFromInputStream(inStream, new File(DB_PATH));
db = SQLiteDatabase.OpenDatabase(DB_PATH, null, SQLiteDatabase.OPEN_READONLY);
}
return db;
}
public static void CreateFileFromInputStream(InputStream inStream, File destination)
{
try
{
OutputStream outStream = new FileOutputStream(destination); // THIS CAUSES THE FAILURE
CopyFile(inStream, outStream);
}
catch (Exception ex)
{
Log.E("OutputStream", ex.Message);
}
}
The exception is not caught in the catch. The file "/data/com.MyApp/databases/dbname" does not yet exist, I assume by reading the docs that it would be created upon instantiating the FileOutputStream.
I am using C# and dot42 and testing on a real device using JellyBean 4.2