Thursday 21 April 2016

Function to Copy Application Db To Download Folder






public static void copyAppDbToDownloadFolder() throws IOException {
   try {
       File backupDB = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Database_BK_UP.db"); // for example "my_data_backup.db"
       File currentDB = ctx.getDatabasePath("Estibyan.db"); //databaseName=your current application database name, for example "my_data.db"
       if (currentDB.exists()) {
           FileInputStream fis = new FileInputStream(currentDB);
           FileOutputStream fos = new FileOutputStream(backupDB);
           fos.getChannel().transferFrom(fis.getChannel(), 0, fis.getChannel().size());
           // or fis.getChannel().transferTo(0, fis.getChannel().size(), fos.getChannel());
           fis.close();
           fos.close();
           Log.i("Database successfully", " copied to download folder");
           
       } else Log.i("Copying Database", " fail, database not found");
   } catch (IOException e) {
       Log.d("Copying Database", "fail, reason:", e);
   }
}

No comments:

Post a Comment

How to do text writing animation?  In Android Development we do not have the option to use any other custom font in our default Tex...