如何在Android中用新的数据库文件替换现有的sqlite数据库文件 [英] How to replace existing sqlite database file with new database file in android
本文介绍了如何在Android中用新的数据库文件替换现有的sqlite数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个使用sqlite数据库的应用程序,我的应用程序中有一个功能带有更新数据库"按钮.
Im doing an app which uses sqlite database There is an feature in my app having a button 'Update Database'.
当用户单击更新数据库"按钮时,我需要使用URL中的新数据库文件来升级旧数据库文件.
When user clicks on the 'Update Database' button i need to upgrade the old db file with new db file from URL.
如何执行此操作.研究告诉我,当数据库放置在.apk文件中时,我们无法更改它.有什么解决办法吗?请帮帮我.谢谢.
How to do this. the research tells me that we cant change a db as it gets place in an .apk file. Is there any solution to this. Please help me out. Thank you.
推荐答案
private void importDatabase(String inputFileName) throws IOException
{
InputStream mInput = new FileInputStream(inputFileName);
String outFileName = YOUR_DB_PATH_HERE;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer))>0)
{
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
您可能会发现它很有帮助:
You may find it helpfull:
这篇关于如何在Android中用新的数据库文件替换现有的sqlite数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文