2
我在我的备份模块从备份恢复SQLite
数据库。首先,它删除当前数据库文件,然后将备份数据库字节复制到数据库目录。一旦数据库恢复,我要求用户重新启动应用程序,包括从内存中删除它。这工作正常。恢复后刷新SQLite数据库引用
有没有办法以编程方式“刷新”数据库文件的引用?用这种方式,用户不必关闭应用程序。
我的数据库存储在/data/data/com.mypackage.project/databases/mydatabase.db
中,备份位于sdcard中。
我恢复的数据库文件是这样的:
public static boolean transferBytes(File from, File to) {
FileChannel inputChannel = getInputStream(from).getChannel();
FileChannel outputChannel = getOutputStream(to).getChannel();
return transfer(inputChannel, outputChannel);
}
private static boolean transfer(FileChannel inputChannel, FileChannel outputChannel) {
try {
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
inputChannel.close();
outputChannel.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
哪里from
是备份文件和to
与上面提到的数据库路径的文件实例。