何处保存只读Android项目* .db文件? [英] Where to save read-only *.db file in android project?

查看:150
本文介绍了何处保存只读Android项目* .db文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,琐碎的问题,我有一个 .db的 sqlite3的文件,我是假设取数据,例如它是只读的。但我不知道在哪里可以导入,同时采取这个数据文件的路径,才能连接呢?你能帮助我吗?

Sorry for trivial question, I've a .db sqlite3 file that I'm suppose to take data, e.g. it's read-only. But I'm wondering where to import it, while taking the path of this data file in order to connect it? Can you help me?

推荐答案

在项目中,我有一个称为资产项目下的文件夹,我把我的* .db的存在,并加载这样的数据库:

In my project I have a folder under the project called assets, I put my *.db there and load the database like this:

private static void copyDatabase(String dbname) throws IOException {
        InputStream is = mContext.getAssets().open(dbname);
        String outFileName = DB_PATH + dbname;
        OutputStream out = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = is.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }
        is.close();
        out.flush();
        out.close();
    }

这篇关于何处保存只读Android项目* .db文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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