0

The application that I work on has a external SQLite database (sitting in the assets folder). My friend is using the same DB file in the iPhone version of the app. Content of the DB file is updated continuously. As both projects are in the same repository we created a Shared folder where we keep the DB file so both of use can link to that shared resource. It works in the iPhone project but fails in Android.

When in Eclipse, I click on the assets/new/file and click on Advanced and then Link to file in the file system. The file appears in the assets folder (in Eclipse) but I cannot access it from JAVA code.

Why that doesn't work? Is there any other was of linking external files to the project in Eclipse?

Thanks

EDITED:

I use this code for opening the assets file:

OutputStream os = new FileOutputStream(db_path + DB_NAME);
byte []b = new byte[1024];
int i, r;

//load list of files from 'data' folder
String[] fileCollection = am.list("data");
Arrays.sort(fileCollection);
for(i=0;i<fileCollection.length;i++)
{
    //String fn = String.format(DB_NAME"%dd.db", (i + 1));
    String fn = DB_NAME + "." + (i + 1);
    if(fileCollection[i].equals(fn) == false){
        break;
    }
    InputStream is = am.open("data/"+fn);
    while((r = is.read(b)) != -1) {
        os.write(b, 0, r);
    }
    is.close();
}
os.close();
1
  • What is your code for accessing that file from asset? Commented Nov 15, 2011 at 12:36

1 Answer 1

1

From, the detail you given in question, I conclude that you can not use database file directly from the asset directory, you have to copy that database file into application's internal storage data/data/database/ and then use it.

EDIT:

I think Android environment can't recognize the physical path of you system files, so when we try to link any file for asset or any folder which are in android project hierarchy then it can not find the file which one linked from a system path.

So to make it working in android you have to put that file in your asset directory physically, not virtually (by putting file link in asset).

Hope I am not wrong in this. If yes then let me know on this topic.

Thanks.

Sign up to request clarification or add additional context in comments.

7 Comments

Please see the updated. I cannot access the a file that I Linked from external folder in the Eclipse. I have to access this file first in order to copy it to the data/data/database folder.
put this line for getting database file from asset, InputStream myInput = Context.getAssets().open("<database file name>"); please don't make a directory structure in asset, just put simple database file in asset.
Removing directory and replacing the code didn't help. I still get java.io.FileNotFoundException: data.sqlite. Could you clarify why I shouldn't create directories in asset folder?
You might be right with the first part of your answer but I will try to dig more to be sure that this cannot be achieved. However, I don't agree with the second part. Android DO support directory structure in assets folder - please see my updated code.
by the way what do you mean by 'by giving linked it' phrase?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.