Export SQLite DB

Andorid 2019. 2. 22. 00:36
728x90
private void exportDB(){
File sd = Environment.getExternalStorageDirectory();
      File data = Environment.getDataDirectory();
       FileChannel source=null;
       FileChannel destination=null;
       String currentDBPath = "/data/"+ "com.authorwjf.sqliteexport" +"/databases/"+DB_NAME;
       String backupDBPath = DB_NAME;
       File currentDB = new File(data, currentDBPath);
       File backupDB = new File(sd, backupDBPath);
       try {
            source = new FileInputStream(currentDB).getChannel();
            destination = new FileOutputStream(backupDB).getChannel();
            destination.transferFrom(source, 0, source.size());
            source.close();
            destination.close();
            Toast.makeText(this, "DB Exported!", Toast.LENGTH_LONG).show();
        } catch(IOException e) {
        e.printStackTrace();
        }
}
728x90
Posted by kjun.kr
,