我的应用程序使用sqlite数据库,该数据库是在资源文件夹中预先创建并在运行时复制的。它通常工作得很好。 我已经重新向数据库添加了一个新列,并增加了数据库版本,以便运行onUpgrade方法。这一切都运行良好,但新数据库被复制没有新添加的列。这是onUpgrade代码:
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
任何想法如何解决?
10X!
答案 0 :(得分:0)
有时需要提出明显的要求。 :)
您确定将新数据库复制到资产文件夹中,以便可以将其再次移动到数据库目录中吗?