final String inFileName = "/data/data/com.aad.lang/databases/ims.db"; File dbFile = new File(inFileName); try{ FileInputStream fis = new FileInputStream(dbFile); String outFileName = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/ims.db"; // Open the empty db as the output stream OutputStream output = new FileOutputStream(outFileName); // Transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; try{ while ((length = fis.read(buffer)) > 0) { output.write(buffer, 0, length); } // Close the streams output.flush(); output.close(); fis.close(); }catch(Exception e){ } }catch (FileNotFoundException e){ }
private void backupDatabase() { try { File sd = Environment.getExternalStorageDirectory(); if (sd.canWrite()) { File file = getDatabasePath("tags.db"); if (file.exists()) { File backupDB = new File(sd, file.getName()); FileChannel src = new FileInputStream(file).getChannel(); FileChannel dst = new FileOutputStream(backupDB).getChannel(); long lBytes = dst.transferFrom(src, 0, src.size()); src.close(); dst.close(); Toast.makeText(this, "Database was successfully backed up to the " + sd + " folder.", Toast.LENGTH_LONG).show(); } } else Toast.makeText(this, "Unable to write to external storage.", Toast.LENGTH_LONG).show(); } catch (Exception e) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)