【发布时间】:2017-01-17 08:32:51
【问题描述】:
我正在尝试将 bike_info.db 恢复到我的应用程序 db文件有一些记录,我想在应用程序中恢复它们
我尝试使用下面的代码,显示 toast 成功但 db 没有恢复,我不知道为什么。谁能帮忙?
rest = (Button) findViewById(R.id.cview_restore);
rest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "com.infyco.kp.new_tab"
+ "//databases//" + "bike_info.db";
String backupDBPath = "//data//bike_info.db"; // From SD directory.
File backupDB = new File(data, currentDBPath);
File currentDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(backupDB).getChannel();
FileChannel dst = new FileOutputStream(currentDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Import Successful!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Import Failed!", Toast.LENGTH_SHORT)
.show();
}
}
});
点击休息按钮后,这是安卓监视器的输出:
01-17 14:00:40.922 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: ViewPostImeInputStage processPointer 0
01-17 14:00:40.962 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: ViewPostImeInputStage processPointer 1
01-17 14:00:41.012 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: #1 mView = android.widget.LinearLayout{9ba3ae9 V.E...... ......I. 0,0-0,0 #102039d android:id/toast_layout_root}
01-17 14:00:41.072 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
01-17 14:00:43.022 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: #3 mView = null
【问题讨论】:
标签: android sqlite android-sqlite