-1

I have a database file in asset folder. I want path of this file. What path(string) i must place for my method parameter?

thank you in advance

starbug
  • 9
  • 1
  • 8
  • possible duplicate of [How to get the android Path string to a file on Assets folder?](http://stackoverflow.com/questions/8474821/how-to-get-the-android-path-string-to-a-file-on-assets-folder) – mbmc Sep 18 '14 at 17:57
  • The InputStream is opened by `final InputStream is = context.getAssets().open("any_folder_structure_under_assets/" + DB_NAME);` – Phantômaxx Sep 18 '14 at 18:01

1 Answers1

0

Put your database into src/main/assets folder dbname.db

And use this code

private static String DB_NAME = "dbname.db";
private static String DB_PATH = "";
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";


private void copyDataBase() throws IOException{
        AssetManager assets = mContext.getAssets();
        InputStream mInput = assets.open("hashvetar.db");
        String outFileName = DB_PATH + DB_NAME;
        OutputStream mOutput = new FileOutputStream(outFileName);
        byte[] mBuffer = new byte[1024];
        int mLength;
        while ((mLength = mInput.read(mBuffer))>0)
        {
           mOutput.write(mBuffer, 0, mLength);
        }
        mOutput.flush();
        mOutput.close();
        mInput.close();
}
ArmDroid
  • 209
  • 1
  • 11