Tutaj jest przykładowo robiony backup bazy danych na karte SD:
try {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
String backupDBPath = File.separator + "DBbackup.db";
File currentDB = getDatabasePath(DatabaseHelper.DATABASE_NAME);
File backupDB = new File(sd, backupDBPath);
backupDB.createNewFile();
InputStream input = new FileInputStream(currentDB);
OutputStream output = new FileOutputStream(backupDB);
byte[] buffer = new byte[1024];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
output.close();
input.close();
Toast.makeText(this, backupDB.toString(), Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}