Sunday, January 29, 2012

Pull DB on SDCard from Application Package

//Call the below block from anywhere


try {
String str=Environment.getExternalStorageDirectory().toString() + File.separator + "GretRepDataBase.db";
copy(new File( "/data/data/in.globalspace.android/databases/GretRepDataBase.db"), new File(str));
 } catch (IOException e) {
 e.printStackTrace();
}


//Writing method to copy db


void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);


// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}

No comments:

Post a Comment