0

ストア内のアプリケーションを新しいデータベースファイルで更新しようとしていますが、実行しようとするとエラーが発生しました...

私のコードに問題があると思います...

    class DatabaseUtilities  {
 public static void createDatabaseIfNotExists(Context context)
            throws IOException {
        boolean createDb = false;
        File dbDir = new File(AppConstants.DB_PATH);
        File dbFile = new File(AppConstants.DB_PATH + AppConstants.DB_NAME);
        if (!dbDir.exists()) {
            dbDir.mkdir();
            createDb = true;
        } else if (!dbFile.exists()) {
            createDb = true;
        } else {
            boolean doUpgrade = true;

            if (doUpgrade) {
                dbFile.delete();
                createDb = true;

            }
        }

        if (createDb) {
            InputStream myInput = context.getAssets().open("altibbi.db");
            OutputStream myOutput = new FileOutputStream(dbFile);
            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }
            myOutput.flush();
            myOutput.close();
            myInput.close();
        }
    }

    public static SQLiteDatabase getDatabase() {
        return SQLiteDatabase.openDatabase(AppConstants.DB_PATH
                + AppConstants.DB_NAME, null,
                SQLiteDatabase.NO_LOCALIZED_COLLATORS);
    }

 }
4

1 に答える 1

0

SQLiteOpenHelperとそのonUpgrade()コールバックを使用してコードを単純化してみませんか?

于 2012-12-03T14:01:15.050 に答える