【发布时间】:2016-06-10 16:56:29
【问题描述】:
我已经成功备份了我的数据库,但问题是我的备份保存在内存中而不是 SD 卡中。
这是我的代码:
public void exportDatabase()
{
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
String currentDBPath = "/data/" + "com.arpanexample.spm" + "/databases/" + Database.DATABASE_NAME;
String backupDBPath = Database.DATABASE_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
try {
FileChannel source = new FileInputStream(currentDB).getChannel();
FileChannel destination = new FileOutputStream(backupDB).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Toast.makeText(context, "Successfully backup your data", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
}
【问题讨论】: