新的Android数据库APP

时间:2016-07-13 20:34:51

标签: android sqlite

我正在尝试为Android手机编写SQLite数据库应用程序。我有一个现有的数据库并创建了DataBaseHelper extends SQLiteOpenHelper

我是Android开发的新手,但我确实有Windows编程经验(C ++,C#,VB.Net ......) 我正在手机上调试。

在那个助手中,我检查了db的存在,这个因为我的预期而失败。 我的电话:

/**
 * Copies your database from your local assets-folder to the just created empty database in the
 * system folder, from where it can be accessed and handled.
 * This is done by transfering bytestream.
 * */
private void copyDataBase() throws IOException{
    //Open your local db as the input stream
    String What=myContext.getAssets().toString();
    InputStream myInput=null;
    OutputStream myOutput=null;

    try
    {
        myInput = myContext.getAssets().open(DB_NAME + ".sqlite");// this works
    }
    catch(Exception ex)
    {
        Log.d("exception",ex.getMessage() );
    }
    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;
    //Open the empty db as the output stream
    try
    {
        myOutput = new FileOutputStream(new File( outFileName + ".sqlite"));
    }
    catch(Exception ex) {
        Log.d("exception",ex.getMessage() );
    }

    try
    {
        myOutput = new FileOutputStream("/data/data/DailyReminder.sqlite");
    }
    catch(Exception ex)
    {
        Log.d("exception",ex.getMessage() );
    }

    byte[] buffer = new byte[1024];
    int length;
    if(myInput!=null && myOutput !=null)
    while ((length = myInput.read(buffer))>0){
        myOutput.write(buffer, 0, length);
    }
    myOutput.flush();
    myOutput.close();
    myInput.close();
}

创建输出文件的所有尝试都失败。

我的Manifest有写权限:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".scrday"
        android:label="@string/title_activity_scrday"
        android:theme="@style/AppTheme.NoActionBar"></activity>
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</application>

我做错了什么?sk / advice?

0 个答案:

没有答案