将外部SQLite数据库添加到android Studio

时间:2016-07-11 09:53:23

标签: android sqlite

我使用" SQLite Expert"创建了一个SQLite数据库。它的名字是" dbtest"。 我将其复制到assets文件夹,当我运行程序时,它会显示此对话框: enter image description here

这是将数据库复制到数据文件夹的方法:

public final String path="data/data/sqlitedatabaseexample.example.ahmad.sqlitedatabaseexample/databases";
    public final String Name ="dbtest";
       public void copydatabase() throws IOException      // method for copy database from assets folder to program's data folder
        {
            OutputStream myoutput = new FileOutputStream(path+Name);   //destination address
            byte [] buffer = new byte [1024];
            int length;

            InputStream myinput = mycontext.getAssets().open("dbtest");  // file name that is in Assets folder
            while ((length = myinput.read(buffer))>0)
            {
                myoutput.write(buffer,0,length);
            }
            myinput.close();
            myoutput.flush();
            myoutput.close();

        }

我该怎么做?(我不想为dbtest添加格式)

1 个答案:

答案 0 :(得分:0)

将外部数据库导入android程序是不正确的。我们可以通过两个类在项目中创建它。