我尝试从外部驱动器(USB)导入数据库文件,以恢复备份数据。该文件存在且路径正确,但未导入数据库,这是我的代码:
File usb = new File("/storage/UsbDriveA/BackupHM/database.db");
File currentDB = getDatabasePath("database.db");
FileChannel source = null;
FileChannel destination = null;
String backupDBPath = "/storage/UsbDriveA/BackupHM/database.db";
File backupDB = new File(usb, backupDBPath);
try {
source = new FileInputStream(backupDB).getChannel();
destination = new FileOutputStream(currentDB).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Toast toast1 = Toast.makeText(getApplicationContext(), ("Restore ok"), Toast.LENGTH_SHORT);
toast1.show();
finish();
} catch (IOException e) {
e.printStackTrace();
Toast toast = Toast.makeText(getApplicationContext(), ("Error!"), Toast.LENGTH_LONG);
toast.show();
}
}
答案 0 :(得分:0)
编码错误。将声明块更改为:
@RepositoryRestController