我正在尝试使用新的数据库文件更新我在商店中的应用程序....但是当我尝试运行它时出现错误...
我认为我的代码有问题...
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);
}
}