Marqs
Marqs

Reputation: 17910

Android: Linking external file to Eclipse project

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();

Upvotes: 0

Views: 856

Answers (1)

user370305
user370305

Reputation: 109247

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.

Upvotes: 1

Related Questions