AndyCr15UK
Lurker
Hi all, I have an app which I would like to export the SQLite database and import it again, like a backup and restore feature. I have code that exports the database to the SD Card like this -
Can anyone help with how I would import it again?
Thanks!
Code:
private void exportDB(){
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
FileChannel source=null;
FileChannel destination=null;
String currentDBPath = "/data/"+ "com.androidandyuk.regularreminders" +"/databases/Reminders";
String backupDBPath = "Reminders.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
try {
source = new FileInputStream(currentDB).getChannel();
destination = new FileOutputStream(backupDB).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Toast.makeText(this, "DB Exported!", Toast.LENGTH_LONG).show();
} catch(IOException e) {
e.printStackTrace();
Toast.makeText(this, "Exported Failed!", Toast.LENGTH_LONG).show();
}
}
Can anyone help with how I would import it again?
Thanks!
Last edited by a moderator: