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

  • Home
  • SEARCH
  • 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 8515687
In Process

The Archive Base Latest Questions

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

I have this code to store a remote sqlite .db file with my android

  • 0

I have this code to store a remote sqlite .db file with my android app:

public String getRemoteCollection(String url, String dbName){
    BufferedInputStream in = null;
    FileOutputStream fout = null;
    dbName="myFile";
    try
    {
        in = new BufferedInputStream(new URL(url).openStream());
        fout = SectionManager.instance.activity.openFileOutput(dbName, Context.MODE_PRIVATE);

        byte data[] = new byte[1024];
        int count;
        while ((count = in.read(data, 0, 1024)) != -1)
            fout.write(data, 0, count);
        if (in != null)
            in.close();
        if (fout != null)
            fout.close();                   
    }
    catch(Exception e){e.printStackTrace();}
    return dbName;
}

I need to open that file with my sqlitemanager, and I have this function, that opens a .db file from assets, but I need to adapt this method to load the file I stored in the previous mentioned method, which is not stored on assets folder. So I must change this method but I don’t know how to do it correctly.

private void generateSQLiteDB(String databaseName) {     // 
        SQLiteDatabase db =  dbHelper.getReadableDatabase(); // by calling this line an empty database will be created into the default system path of this app - we will then overwrite this with the database from the server
        db.close();
        OutputStream os = null;
        InputStream is = null;
        try{
            is =  ctx.getAssets().open(databaseName+".db");
            String packageName=SectionManager.instance.activity.getApplicationContext().getPackageName();
            //os = new FileOutputStream("/data/data/com.android.launcher/databases/"+databaseName+".db");   
            os = new FileOutputStream("/data/data/"+packageName+"/databases/"+databaseName+".db");  
            copyFile(os, is);
        }catch (Exception e) {
            Log.e("DB", "Database not found", e);                          
        }finally{
            try{
                //Close the streams
                if(os != null)
                    os.close();
                if(is != null)
                    is.close();
            } catch (IOException e) {Log.e("DB", "Can't close adapters");}
        }
    }
  • 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-11T05:13:04+00:00Added an answer on June 11, 2026 at 5:13 am

    openFileOutput(), as the documentation states, does not take a path, the file is stored as part of your app’s ‘private data storage’, which is inaccessible to other apps on the device. So assuming your two code snippets above are in the same Android app, you don’t need to worry about the path, just pass the same file name to openFileInput() and you’ll get the same data that you stored.

    In your case, your file name is dbName, so in your second snippet:

    is =  ctx.getAssets().open(databaseName+".db");
    

    becomes

    is = ctx.openFileInput(databaseName);
    

    which appears to be hard-coded to ‘myFile’ in the first snippet. I am assuming here that ctx is of type Context or a derived class such as Activity.

    UPDATE: If you really need to find out the file system directory being used to store your apps private files, you can call:

    ctx.getFilesDir();
    

    or

    ctx.getFileStreamPath(databaseName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this code to store Object to a file: try{ FileOutputStream saveFile=new
In one page of our site, I have this code: $_SESSION['returnURL'] = /store/checkout/onepage; and
Im create this code to store page view in database, but i have problem
I have made this code to open a database(created in SQLite browser) stored in
This app already exists in the Apple App store and Android markets. It is
I have an android app, that connectos to the remote database with PHP+json but
In my global.asax.vb file, I have code to re-write the URL if there is
I currently have this code which stores XML into an XML-type column called data,
I have stored 6 records in mysql db,when i use this code each of
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2

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.