移动我的数据库到SD卡不工作 [英] Moving my db to sd card not working

查看:159
本文介绍了移动我的数据库到SD卡不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code,试图将我的数据库文件,以我的SD卡。我有不同之处在于我获得下 SD A红线没有问题。有任何想法吗?

I'm using the code below to try and move my database file to my sdcard. I have no problems except that I get a redline under sd. Any ideas?

File data = Environment.getDataDirectory();
if (sd.canWrite()) {
    String currentDBPath = "\\data\\application.package\\databases\\name";
    String backupDBPath = "name";
    File currentDB = new File(data, currentDBPath);
    File backupDB = new File(sd, backupDBPath);
    if (currentDB.exists()) {
        FileChannel src;
    try {
    src = new FileInputStream(currentDB).getChannel();
        FileChannel dst = new FileOutputStream(backupDB).getChannel();
        try {
        dst.transferFrom(src, 0, src.size());
    src.close();
            dst.close();
        } catch (IOException e) {                                                    
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }

推荐答案

您只能使用一个变量,如果你创建了一个实例:

You can only use a variable if you create an instance of it:

将这个:

File sd = Environment.getExternalStorageDirectory();

这篇关于移动我的数据库到SD卡不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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