数据库显示在仿真器,但不是我的Andr​​oid设备上 [英] Database is shown in emulator but not on my android device

查看:215
本文介绍了数据库显示在仿真器,但不是我的Andr​​oid设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code ...

 私有静态字符串DB_NAME =pa1.db;
私人静态字符串DB_PATH =/data/data/in.bit$c$c.sn/databases/;
私人无效copyDataBase()抛出IOException    InputStream的myInput = context.getAssets()开(DB_NAME)。    字符串outFileName = DB_PATH + DB_NAME;    的OutputStream myOutput =新的FileOutputStream(outFileName);    字节[]缓冲区=新的字节[1024];
    INT长;
    而((长度= myInput.read(缓冲液))大于0){
        myOutput.write(缓冲液,0,长度);
    }    myOutput.flush();
    myOutput.close();
    myInput.close();}


解决方案

您不能写入 /数据文件夹中。这是一个Android系统文件夹。它的工作原理在模拟器,因为你是模拟器的 的,而你可能不会在你的设备。

也许你想使用 Android的集成备份API 代替本

Here is my code...

private static String DB_NAME = "pa1.db";
private static String DB_PATH = "/data/data/in.bitcode.sn/databases/";
private void copyDataBase() throws IOException {

    InputStream myInput = context.getAssets().open(DB_NAME);

    String outFileName = DB_PATH + DB_NAME;

    OutputStream myOutput = new FileOutputStream(outFileName);

    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }

    myOutput.flush();
    myOutput.close();
    myInput.close();

}

解决方案

You cannot write to /data folder. This is an Android system folder. It works in the emulator because in the emulator you're root, while you're probably not in your device.

Maybe you want to use Android's integrated backup API instead of this.

这篇关于数据库显示在仿真器,但不是我的Andr​​oid设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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