试图从数据复制的SQLite数据库到SD卡 [英] Trying to Copy SQLite DB from data to SD card

查看:136
本文介绍了试图从数据复制的SQLite数据库到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我使用的是地方张贴在计算器和修改我的目的,以下code:

So I am using the following code that was posted somewhere on StackOverflow and modified for my purposes:

try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//"+ "com.exercise.AndroidSQLite" +"//databases//"+"MY_DATABASE";
            String backupDBPath = "/temp/MY_DATABASE";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

                FileChannel src = new FileInputStream(currentDB).getChannel();
                FileChannel dst = new FileOutputStream(backupDB).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
                Toast.makeText(getBaseContext(), backupDB.toString(), Toast.LENGTH_LONG).show();

        }
    } catch (Exception e) {

        Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();


    }
}

所以我得到的,当我尝试访问它的错误是:

So the error I get when I try to access it is:

java.io.FileNotFoundException: /data/data/com.exercise.AndroidSQLite/databases/MY_DATABASE: open failed: EACCES (Permission Denied)

我试图复制此文件,而不生根我的平板电脑。写外部存储目录权限设置中的应用;我只是无法避开这个错误。将就解决这一问题AP preciate的帮助下,它的驾驶我疯了

I am trying to copy this file without rooting my tablet. The write external storage directory permission is set in the application; I just can't get around this error. Would appreciate help on resolving this issue, it's driving me mad

推荐答案

您使用的是MY_DATABASE字面上的时候,你可能真的想使用它作为一个变量...

You are using "MY_DATABASE" literally when you probably actually want to use it as a variable...

从周围删除引号,看看是否能不能解决你的问题。

Remove the quotes from around it and see if that doesn't solve your problem.

这篇关于试图从数据复制的SQLite数据库到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆