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 6837977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:32:30+00:00 2026-05-26T23:32:30+00:00

I have a database created from a file in my assests folder. When the

  • 0

I have a database created from a file in my assests folder. When the app is upgraded I want the new file in that folder to add (append) to the current database. I am currently trying to use this script below, but it is not working. I is just not adding to the db.

        //Open your local db as the input stream
        InputStream myInput = myContext.getAssets().open(STATIC_DB_NAME);

        // Path to the just created empty db
        String outFileName = STATIC_DB_PATH + STATIC_DB_NAME;

        //Open the empty db as the output stream
        OutputStream 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);
        }

        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close(); 
  • 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-26T23:32:31+00:00Added an answer on May 26, 2026 at 11:32 pm

    You should look at using the SQLLiteOpenHelper and implementing the onUpgrade method. In that method (only called when your database version number — something you maintain– is incremented), you can then open your asset file and use it to execute inserts/updates into the sqllite DB.

    So in this case, store the SQL commands in the file and then read each line and run with db.execSQL:

    BufferedReader reader = new BufferedReader(new FileReader(STATIC_DB_NAME));
    String line  = reader.readLine();
    while(line != null){
      db.execSQL(line); 
      line = reader.readLine();
    }
    reader.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Oracle database backup file (.dmp) that was created with expdp .
I have a dataset that is dynamically created from a csv file. What I
I have created this php script, to create an xml-file from my database: <?php
Problem: I have file named by their Id from database. And when somebody want
I have a regex created from a list in a database to match names
I have created a Windows Service in VB.net for building xML from a database.
I have a database that I have created using SQL Server Developer 2008. I
So, I have this code that grabs a bunch of data from the database,
I have a database and I've created a DBML Linq-to-SQL file to represent this
I have an MDF file and no LDF files for a database created in

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.