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);
}
}
답변을 찾으려면 여기를 클릭하십시오. http://stackoverflow.com/questions/9109438/how-to-use-an-existing-database-with-an-android-application/9109728#9109728 –
whats the error? – zennon
은 Logcat에서 오류를 공유합니다 – Androider