Created
September 18, 2014 14:03
-
-
Save sergiandreplace/ae0e7d95d03af321b96c to your computer and use it in GitHub Desktop.
Export database to sd card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void exportDatabse(String databaseName) { | |
try { | |
File sd = Environment.getExternalStorageDirectory(); | |
File data = Environment.getDataDirectory(); | |
if (sd.canWrite()) { | |
String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+""; | |
String backupDBPath = "backupname.db"; | |
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