English 中文(简体)
FrankiteException whenplicaing/decompressing a zipped DB onto Anders
原标题:SQLiteException when copying/decompressing a zipped DB onto Android

目前,我正在将一个数据库从我的资产夹到数据/数据/包装夹。 这是法典(。 (a) 《公约》第22条第1款(a)项。

public void copyDataBase() throws IOException{
    // open db as input stream
    InputStream myInput;
    //open empty db as output stream
    OutputStream myOutPut;
    try {
        myInput = myContext.getAssets().open(DB_NAME);

        //path to newly created db
        String outFileName =DB_PATH + DB_NAME;

        myOutPut = new FileOutputStream(outFileName);

        //transfer bytes from the inputFile to the outPutFile
        byte[] buffer = new byte[1024];
        int length;
        while((length = myInput.read(buffer))>0){
            myOutPut.write(buffer, 0, length);
        }
        myOutPut.flush();
        myOutPut.close();
        myInput.close();
        }
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

现在,为了节省下载的篇幅,我正试图在将文件复制到数据/数据/包装的夹头之前将文件zi。

private void copyDataBaseFromZipFile() {
    InputStream inputStream = null;
    OutputStream outputStream = null;

    String sourcePathname = this.getBundledPathname();
    String destinationPath = this.getDatabasePathname();

    try {
        inputStream = this.mContext.getAssets().open(sourcePathname);
        ZipInputStream zipStream = new ZipInputStream(inputStream);

        int BUFFER = 8096;
        outputStream = new FileOutputStream(destinationPath);
        BufferedOutputStream dest = new BufferedOutputStream(outputStream, BUFFER);

        ZipEntry entry;
        while ((entry = zipStream.getNextEntry()) != null) {
            if (entry.getName().equals("androidDB.sql")) }
                int count;
                byte data[] = new byte[BUFFER];
                while ((count = zipStream.read(data, 0, BUFFER)) != -1) {
                    dest.write(data, 0, count);
                }
            }
        }

        outputStream.flush();
        outputStream.close();

        dest.flush();
        dest.close();

        zipStream.close();

        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

当我试图稍后开放数据库时(有KingDatabse),我发现这一错误:android.database.sqlite.SQLiteException:不能开放数据库

除I m复制件外,我没有改动过任何东西,这只是我以前复制的版本。 最终数据库是正确的规模,因此似乎仍然压缩了。 如果任何人有任何建议或可能的理由,我们会赢得开放,将非常感谢。

最佳回答

您应删除这些内容:

outputStream.flush();
outputStream.close();

页: 1 也许有些是用tes进行缓冲的,但自您关闭outputStream以来。 在请上<代码>dest.flush()之前,从来不实际写到档案中。

问题回答

暂无回答




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签