无法在数据库文件夹中创建文件

时间:2013-10-04 08:56:05

标签: c# android sqlite fileoutputstream dot42

我正在尝试将现成的sqlite v3数据库从我的assets文件夹复制到我的应用程序的/ databases文件夹中。但是我得到了一个java运行时异常。

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);
            }
        }

捕获中没有捕获异常。文件“/data/com.MyApp/databases/dbname”尚不存在,我通过阅读文档来假设它将在实例化FileOutputStream时创建。

我正在使用C#和dot42并使用JellyBean 4.2在真实设备上进行测试

0 个答案:

没有答案