android - copying a file from assets to databases folder data missing

I have a pre-existing sqlite database that is about 5mb in size. I use this code to copy from my assets folder to the packages/databases folder on the device.

The database copies to the device but the data inside the database has been deleted or is missing. The only table inside is called android_metadata.

Here is the code:

        InputStream myInput = myContext.getAssets().open(DB_NAME);

        // Path to the just created empty db
        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 =>0){
            myOutput.write(buffer, 0, length);

        //Close the streams
        }catch(SQLiteException e){


If your database (tables) is (are) not appearing / loading, then it is likely that you have created it inproperly. I would go back and ensure that you have set it up correctly.

May be you should refer to this link: Database not copying from assets

Make sure your database is in YourAppName\assets\databases folder.

For example, if your database name is: app.db, it should be in that folder to be copied.

You need to reinstall your app whenever you want to release a new copy of the database.

If you are using the SQLiteAssetHelper, your class file will look somewhat like this:

package com.mycompany.myapp;

import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

public class MyDatabase extends SQLiteAssetHelper {

    private static final String DATABASE_NAME = "app.db";
    private static final int DATABASE_VERSION = 1;

    public MyDatabase(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

        // you can use an alternate constructor to specify a database location
        // (such as a folder on the sd card)
        // you must ensure that this folder is available and you have permission
        // to write to it
        // super(context, DATABASE_NAME, context.getExternalFilesDir(null).getAbsolutePath(), null, DATABASE_VERSION);


    public Cursor mymethod (String param) {
        SQLiteDatabase db = getReadableDatabase();

        String sql;
        sql = "...";

        Cursor c = db.rawQuery(sql, new String[] { param  });

        return c;

Need Your Help

How to force file download with PHP

php file download

I want to require a file to be downloaded upon the user visiting a web page with PHP. I think it has something to do with file_get_contents, but am not sure how to execute it.