Skip to content

Instantly share code, notes, and snippets.

@prasannaboppe
Created October 11, 2017 09:15
Show Gist options
  • Save prasannaboppe/83dea39ee1822e4d722d134426d1a0ba to your computer and use it in GitHub Desktop.
Save prasannaboppe/83dea39ee1822e4d722d134426d1a0ba to your computer and use it in GitHub Desktop.
Export Sqlite Database
public void exportDatabase() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "path to db";
String backupDBPath = "path to export";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment