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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:07:33+00:00 2026-06-10T11:07:33+00:00

I have an sqlite file in the assets folder. I’m using a database manager

  • 0

I have an sqlite file in the assets folder. I’m using a database manager class that has been referenced thousands of times in other stack overflow posts: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

private void copyDatabase() throws IOException {
        // Open your local db as the input stream
        InputStream myInput = context.getAssets().open( DB_NAME );

The problem is the open() method (or getAssets?) that keeps throwing an IOException. My path and file names:

private static final String DB_NAME = "attractioninfo";
private static final String DB_PATH = "/data/data/seattle.tourists/";

Another related question I have is about the path. I’ve checked the files on my testing phone (samsung galaxy sII) but I don’t see a /data/data/mypackagename/… anywhere. Where exactly is this in internal storage? I am using Android 2.2.

EDIT: I did more testing and I’ve also found that on first install (this means that there is no database file on the phones internal storage yet, it needs to be copied there) this line doesn’t work either (I get an SQLiteException)

private boolean checkDatabase() {
    SQLiteDatabase checkDB = null;

    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase( myPath, null, SQLiteDatabase.OPEN_READONLY );

FULL CODE:

package seattle.tourists;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;
import android.content.res.AssetManager;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
    private static final String DB_NAME = "attractioninfo";
    private static final String DB_PATH = "/data/data/seattle.tourists/databases/";
    private static final int DB_VERSION = 1;
    private static final String TABLE_NAME = "ExtraInfo";

    private SQLiteDatabase db;
    private final Context context;

    /**
     * Constructor
     * @param context application context
     */
    public DatabaseHelper( Context context ) {
        super( context, DB_NAME, null, DB_VERSION );
        this.context = context;
    }

    /**
     * Creates empty database on system and rewrites it with existing database
     * @throws IOException
     */
    public void createDatabase() throws IOException {
        boolean dbExist = checkDatabase();

        if ( dbExist ) {
            // do nothing, the database already exists;
        }
        else {
            this.getReadableDatabase();

            try {
                copyDatabase();
            }
            catch ( IOException e ) {
                throw new Error( "Error copying database" );
            }
        }
    }

    /**
     * Check to see if a database exists
     * @return true if database exists, false otherwise;
     */
    private boolean checkDatabase() {
        SQLiteDatabase checkDB = null;

        try {
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase( myPath, null, SQLiteDatabase.OPEN_READONLY );
        }
        catch ( SQLiteException e ) {
            int x = 5;
        }

        if ( checkDB != null )
            checkDB.close();

        return checkDB != null ? true : false;
    }

    /**
     * Copes database from assets-folder to system folder, where it can be
     * accessed and handled. This is done by transferring byte-stream.
     * @throws IOException
     */
    private void copyDatabase() throws IOException {
        // Open your local db as the input stream
        AssetManager assets = context.getAssets();
        InputStream myInput = assets.open( DB_NAME );

        String outFileName = DB_PATH + 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();
    }

    public SQLiteDatabase openDataBase() throws SQLException {
        // Open the database
        String myPath = DB_PATH + DB_NAME;
        return db = SQLiteDatabase.openDatabase( myPath, null, SQLiteDatabase.OPEN_READONLY );
    }

    public synchronized void close() {
        if ( db != null )
            db.close();

        super.close();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // do nothing
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // do nothing
    }
}
  • 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-06-10T11:07:35+00:00Added an answer on June 10, 2026 at 11:07 am

    Found that I was using the wrong file format. I was using an txt/SQL format and not sqlite.

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

Sidebar

Related Questions

I have my code below. It correctly reads my sqlite database file(that i have
I have an SQLite database file, created using Sqliteman admin utility. I copied the
I have created a SQLite file and putted it on to assets folder. Now
I have a *.sqlite file... but I need the database in *.sl3 format? What
I have an SQLite database file exported from Scraperwiki with .sqlite file extension. How
I have a script file for parsing through a SQLite database. I now need
I have written an Android application that uses SQLite database which is saved in
I have a SQlite database file with records which comes with my app. I
i have a well pre-populated sqlite file that i copied into my project (in
Suppose that I have a huge SQLite file (say, 500[MB]). Can 10 different python

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.