Android手机未root手机获取应用的sqlite数据库

//找到文件的路径  /data/data/包名/databases/数据库名称
File dbFile = new File(Environment.getDataDirectory().getAbsolutePath() + "/data/" + mContext.getPackageName() + "/databases/你自己的数据库名称.db");
FileInputStream fis = null;
FileOutputStream fos = null;
try {
    //文件复制到sd卡中
    fis = new FileInputStream(dbFile);
    fos = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/copy_database.db");
    int len = 0;
    byte[] buffer = new byte[2048];
    while (-1 != (len = fis.read(buffer))) {
        fos.write(buffer, 0, len);
    }
    fos.flush();
} catch (Exception e) {
    e.printStackTrace();
} finally {
    try {
        if (fos != null) fos.close();
        if (fis != null) fis.close();
        Toast.makeText(mContext, "copy结束", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

你可能感兴趣的:(Android手机未root手机获取应用的sqlite数据库)