In my Android app, I load a file and a folder containing a bunch of files. I am trying to determine whether these should be added as assets, as resources or something else entirely.
The file is an XML file whose path gets passed to a class constructor that creates an object from what’s contained in the file. I have access to the constructor code if needed.
The folder contains a bunch of specially-formatted non-human-readable files. The path to the folder gets passed to another constructor that knows the structure of the folder and it creates an object. I don’t have access to its code.
Oh, and these two have nothing to do with each other, other than the fact that they are needed by the same app.
So how should I store these? I first thought about adding them as assets but apparently I can only get an input stream for an asset which would not work. If I add the folder as a resource, does it have to go into a specific subfolder under res/? Which one? Does te XML file have to be placed under res/xml? Whether an asset or a resource, is there a default root path that I should use to access the file and the folder?
Thx!
I would put the XML file under
res/xml/, simply for performance reasons.res/xml/supports arbitrary XML, and all XML-encoded resources are parsed about 10 times faster than parsing ordinary files. Your “class constructor that creates an object from what’s contained in the file” would use theXmlResourceParseryou get from theResourcesobject for that XML.In terms of the folder, use
assets/, as you cannot have a folder structure in resources (raw or otherwise).You don’t really have a choice if you wish to package the files with your app and use them directly. Neither resources nor assets are available as files directly. The only way to get their contents as files is for you to copy them, using streams, to local files yourself, which increases the amount of storage they take up and, in the case of the XML, reduces parsing performance.