Zach
Zach

Reputation: 10129

Where to place a xml file in android project?

For my project I am using an xml file to fetch information. I know this can be stored inside assets folders or inside resources/raw folder. My issue is I have to modify the xml dom and write back to the file again as a persistent storage.

I have read that I cant write back to a file in assets folder. But no idea regarding the file in resource folder?

Where can I keep the file for this purpose? Is storing the file in sdcard the only possible option?

Thanks

Upvotes: 0

Views: 1699

Answers (2)

Ashl
Ashl

Reputation: 1259

I would include the file in res/raw and then create a local copy in the file directory for your app. On app init, you can check to see if it exists in the external storage and then if it does not, load it anew from res/raw.

Without going too far into the nitty-gritty, something like this perhaps:

File filesDir = context.getFilesDir();
File xml = new File(filesDir, YOUR_FILE_NAME);
if(xml.exists() {
    /* load data from filesDir */
} else {
    /* load data from res/raw and save to filesDir */
}

Upvotes: 2

faylon
faylon

Reputation: 7450

Is storing the file in sdcard the only possible option?

Yes, and you can also store the file in internal memory.

You do not have the permission to modify the apk files.

Upvotes: 1

Related Questions