I am trying to backup an android sqlite db. if i run the code one folder is created as i given in program.But that folder is empty,Please help me backup my database and how can i view it. Am using Firefox sqlite manager.Help me to backup my db when i click a button backup db.
My code:
public void exportDatabase(String databaseName) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+"";
String backupDBPath = "PRIM.sqlite";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
System.out.println("@@ Enter 12222222222222");
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();
System.out.println("@@ Enter 2");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}