Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void DBBackup() {
- try {
- File sd = Environment.getExternalStorageDirectory();
- File data = Environment.getDataDirectory();
- if (sd.canWrite()) {
- String currentDBPath = "/data/com.jti.mikee.jti_pos/databases/" + DBHelper.DB_NAME;
- String backupDBPath = "DBTRYBACKUP";
- 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 (Throwable e) {
- e.printStackTrace();
- }
- }
- try {
- File sd = android.os.Environment.getExternalStorageDirectory();
- if (sd.canWrite()) {
- File backupDB = new File("/storage/emulated/legacy/DBTRYBACKUP");
- File currentDB = new File(getDatabasePath(DBHelper.DB_NAME).getPath());
- FileChannel src = new FileInputStream(backupDB).getChannel();
- FileChannel dst = new FileOutputStream(currentDB).getChannel();
- dst.transferFrom(src, 0, src.size());
- src.close();
- dst.close();
- Toast.makeText(getApplicationContext(), "Import Successful!", Toast.LENGTH_SHORT).show();
- }
- } catch (Throwable e) {
- Toast.makeText(getApplicationContext(), "Import Failed!", Toast.LENGTH_SHORT).show();
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment