05-06-2010 07:53 PM - edited 05-06-2010 07:57 PM
I have my BB application configuration in a file config.properties and I don't know how to access this file, get the properties, store them in a object that I can later access to find my properties with a specific methods like
public String getProperty(String key);
public void store(String key, String value);
public void save(InputStream file);
I'm completely lost and really don't know how to do and where to start.... I know there is a topic on how to read a file but that's almost nothing, I need to store somewhere the config and access it easily.
Example of file "config.properties":
logo = powered_by.gif
shortcut = shortcut.gif
camera = camera.gif
# Text files
city.list = /city.list
license.file = /license.txt
help.file = /help.txt
I know here is the Properties class but not available in the Blackberry SDK 4.5. I think it's what I need to do what I want.
Any help is welcome!
And if you know a better solution to manage config files on the Blackberry SDK (4.5), using .properties files, xml or whatever, please tell me!
05-06-2010 08:57 PM
I would embed the file in the COD distribution, read and parse it, and store the name/value pairs in a hash table.
The Hashtable class can then be stored in the Persistence store.
See this article on embedding a file in your COD:
05-06-2010 09:06 PM
It is embed. The file is at the root directory in my project.
If you have example of parsing a file like this, and store in an hashtable, I take it!
I will try to find how to do that in the same time.
05-06-2010 09:48 PM
Each line of you data is split by the '=' character, right? This is not hard to parse.
You wind up with two strings, name and value
You place these in a hastable using Hashtable.put(name,value)
See the javadocs, everything you need is there.
05-07-2010 07:31 PM
I will use Hashtable to store the properties. I always wanted to do what you said, but i have no idea how to do everything in Java with Blackberry JDE 4.5: open and read a file at the root of my project (same place as where the Blackberry_App_Descriptor.xml is), and parse it (that I have never done before).
If you have links or examples, you're more than welcome!
05-07-2010 08:08 PM
There is an example in the article I linked for you.
In order to get the file on the device, it needs to be part fo the distribution, hence it is added to your project and consequently your COD file.
Is this not sufficient?