How to copy another database apps to SDCard

I've install an application to my device. But i want to copy that database to SDcard to be used by my apps. I used this code to copy database. But it's failed. And need "su" command

public void copydatabase() throws IOException{
    String [] cmd1 = { "su", "cp", "/data/data/com.apps/databases/data01.db", "/mnt/extSdCard/data01.db"};
    Process process = new ProcessBuilder(cmd1).start();
    try {
        process.waitFor();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Any some code to copy that to SDCard without "su" command??

Answers


public static void copyDataBase(Context mActivity) throws IOException {
        InputStream myInput = new FileInputStream(
                new File("/data/data/" + mActivity.getPackageName()
                        + "/databases/" + "xyz.sqlite"));
        File files = new File("/sdcard/files/");
        files.mkdirs();
        String outFileName = "/sdcard/files/xyz.sqlite";
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int bufferLength;
        while ((bufferLength = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, bufferLength);
        }
        myOutput.flush();
        myOutput.close();
        myInput.close();
    }

I hope its useful to you...


Need Your Help

How to get coordinates of an address in android

android google-maps google-maps-api-3 gps

How do i get gps co-ordinates of the location/address entered by user in android ?