是的,我们可以以不同的方式执行此操作。使用此逻辑,您将获得SDcard中的数据库。
String sourceLocation = "/data/data/com.sample/databases/yourdb.sqlite" ;// Your database path
String destLocation = "yourdb.sqlite";
try {
File sd = Environment.getExternalStorageDirectory();
if(sd.canWrite()){
File source=new File(sourceLocation);
File dest=new File(sd+"/"+destLocation);
if(!dest.exists()){
dest.createNewFile();
}
if(source.exists()){
InputStream src=new FileInputStream(source);
OutputStream dst=new FileOutputStream(dest);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = src.read(buf)) > 0) {
dst.write(buf, 0, len);
}
src.close();
dst.close();
}
}
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}你必须给予许可