如何读取android asserts下面已经存在的sqlite数据库

如何读取android asserts下面已经存在的sqlite数据库,第1张

这个可以在每次应用开启时检测database文件夹下是否有这个名称的数据库,如果没有就从asserts中获得释放一次,给你看一下我的代码:

我的asserts里有一个文件叫做:addressdb

/

在onCreate()方法中调用

/

private File initDatabase (){

        BufferedInputStream     bis = null;

        BufferedOutputStream    bos = null;

        File                    file = getDatabasePath("addressdb");

        byte []                 buffer = new byte[1024];

        int                     c;

        try {

            if (!fileexists())

                filegetParentFile()mkdirs();

            else

                return file;

            bis = new BufferedInputStream(getAssets()open("addressdb"));

            bos = new BufferedOutputStream(new FileOutputStream(file));

            while ((c = bisread(buffer)) != -1)

                boswrite(buffer, 0, c);

        } catch (IOException e) {

            eprintStackTrace();

            return null;

        }finally{

            try {

                if (bis != null)

                    bisclose();

                if (bos != null) {

                    bosclose();

                    bosflush();

                }

            }catch (IOException e){

                eprintStackTrace();

            }

        }

        return file;

    }

一般MySQL都不由APP进行直接的远程连接,而是交由后台服务器进行封装处理的。

举个例子。APP访问--》后台PHP服务器--》PHP访问本地MySQL数据库--》PHP返回查询给APP

所以,一般的APP分为两部分,APP前端开发,PHP后台开发

以上就是关于如何读取android asserts下面已经存在的sqlite数据库全部的内容,包括:如何读取android asserts下面已经存在的sqlite数据库、android app如何从数据库中获取需要的数据、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10152326.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存