Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7046185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:37:13+00:00 2026-05-28T02:37:13+00:00

Currently, I am copying a database from my assets folder to the to the

  • 0

Currently, I am copying a database from my assets folder to the to the /data/data/package folder. This is that code (from the answer here), which works:

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();
    }
}

Now in order to save space in the .apk download, I am trying to zip the file before copying it to the /data/data/package folder.

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();
    }
}

When I attempt to open the database later (with SQLiteDatabse), I get this error: android.database.sqlite.SQLiteException: unable to open database file

I haven’t changed anything except the file I’m copy from, which is only a zipped version of the one I was previously copying over. The final database is the right size, so it doesn’t seem to be still compressed… If anyone has any suggestions or possible reasons WHY it won’t open, it would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:37:13+00:00Added an answer on May 28, 2026 at 2:37 am

    You should remove these lines:

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

    Your BufferedOutputStream probably has some buffered bytes, but since you close outputStream before you call dest.flush(), those bytes are never actually written to the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm doing some unit tests which are executed from bash. Unit tests are
I am currently copying a lot of diagrams from excel to word via macro.
I have a desktop (winforms) application that uses a Firebird database as a data
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently I know of only two ways to cache data (I use PHP but
Currently, I am developing a product that does fairly intensive calculations using MS SQL
I have a MySQL table from a third-party application that has millions of rows
I'm currently considering a number of options for copying an excel sheet into a
I'm copying files from the desktop to a WinCE device (via the RAPI API
Currently migrating from SQL Server to PostgreSQL and attempting to improve a couple of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.