我正在创建一个应用程序,其中客户端将存储记录,因此保持备份这些记录非常重要。
备份文件在Android设备的MyFiles中创建。 当我尝试恢复它时......我正在获取FileNotFoundException。
这是代码
public void importData()
{
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath="/data/"+ "com.example.mypatientsmanager" +"/databases/"+"PatientsDB";
String backupDBPath="PatientsRecord"; // From SD directory.
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if(backupDB.exists())
{
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(ctx, "Import Successful!",
Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(ctx, "Import UnSuccessful!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Log.e("error",e+"");
Toast.makeText(ctx, "Import Failed!", Toast.LENGTH_SHORT)
.show();
}
`
请帮帮我。