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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:11:02+00:00 2026-06-12T09:11:02+00:00

I am trying to copy a database named adinpect from the asset folder to

  • 0

I am trying to copy a database named “adinpect” from the asset folder to the application databases folder, but it is not working…

Code (in main activity onCreate(), just for testing):

 try {
        String destPath = "/data/data/" + getPackageName() + "/databases";
        File f = new File(destPath);

        if (!f.exists()) {

            f.mkdirs();
            f.createNewFile();
            //---copy the db from the assets folder into the databases folder---
            CopyDB(getBaseContext().getAssets().open("adinspect"), new FileOutputStream(destPath + "/adinspect"));
        }

    } 
        catch (FileNotFoundException e) {
            e.printStackTrace();
    }   catch (IOException e) {
            e.printStackTrace();
    }


 public void CopyDB(InputStream inputStream, OutputStream outputStream) throws IOException {

        //---copy 1K bytes at a time---
        byte[] buffer = new byte[1024];
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
        }

        inputStream.close();
        outputStream.close();

}//end copyDB

The “databases” folder is created but there in nothing in it, trying to access it by DDMS.

I do not get any errors.

Any suggestion?

Thanks

  • 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-12T09:11:03+00:00Added an answer on June 12, 2026 at 9:11 am

    This code wlll help you to copy DB from assets folder.
    You can check first if DB exists or not.

    try{
        // CHECK IS EXISTS OR NOT
        SQLiteDatabase dbe = SQLiteDatabase.openDatabase("/data/data/"+getPackageName+"/databases/dbname.sqlite",null, 0);
        dbe.close();
    }
    catch(Exception e)}
    {
        // COPY IF NOT EXISTS
        AssetManager am = getApplicationContext().getAssets();
        OutputStream os = new FileOutputStream("/data/data/"+getPackageName+"/databases/dbname.sqlite");
        byte[] b = new byte[100];
        int r;
        InputStream is = am.open("dbname.sqlite");
        while ((r = is.read(b)) != -1) {
             os.write(b, 0, r);
       }
       is.close();
       os.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to copy a 5mb database file to data folder from raw
I'm Unable to copy SQLite database from assests folder to device memory(trying on emulator).
Trying to insert data in database from edittext in android but data is not
I am trying to copy all format file (.txt,.pdf,.doc ...) file from source folder
I'm trying to generate scripts from a database, but with slight modifications to those
Using MongoDB I'm trying to copy a database from one server to another. My
I am trying to copy my pre-populated database to a writable directory (I am
I'm trying copy a single file from the Plugin directory inside of my Wordpress
I am trying to copy files from a directory that is in constant use
I am trying to copy and paste a folder structure on file system programmatically.

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.