私はデータベースを持っていて、アプリケーションの次の更新時にそのデータベースを変更したいのですが、データベース(アプリケーションディレクトリ内)の現在のデータを失いたくないのです。そのデータを新しいデータベースにコピーして削除する必要があります古いデータベース..どうすればそれを達成できますか?それについて他に何か考えがありますか...
前もって感謝します..
これは私の現在のデータベースコードです...
public class DbUtils {
public static String DB_PATH;
private String DB_NAME;
File dbDir;
private SQLiteDatabase dataBase;
public DbUtils(File fileDirectory, String sqliteFileName) {
this.DB_NAME = sqliteFileName;
dbDir = fileDirectory;
}
public void createDatabaseIfNotExists(Context context) throws IOException {
boolean createDb = false;
File dbFile = new File(dbDir.getAbsolutePath() + "/" + DB_NAME);
DB_PATH = dbFile.getAbsolutePath();
if (!dbDir.exists()) {
dbDir.mkdir();
createDb = true;
} else if (!dbFile.exists()) {
createDb = true;
} else {
boolean doUpgrade = false;
if (doUpgrade) {
dbFile.delete();
createDb = true;
}
}
if (createDb) {
InputStream myInput = context.getAssets().open(DB_NAME);
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 SQLiteDatabase getStaticDb() {
return dataBase = SQLiteDatabase.openDatabase(DB_PATH, null,
SQLiteDatabase.OPEN_READWRITE);
}
public void closeDataBase(){
if(dataBase!=null && dataBase.isOpen()){
dataBase.close();
}
}
}