Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Contributor
dachmt
Posts: 25
Registered: ‎04-16-2010

Read .properties file

[ Edited ]

Hi,

 

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":

# Images
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!

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008

Re: Read .properties file

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:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To_...

 

 

Please use plain text.
Contributor
dachmt
Posts: 25
Registered: ‎04-16-2010

Re: Read .properties file

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.

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008

Re: Read .properties file

Each line of you data is split by the '=' character, right? This is not hard to parse.

 

name=value

 

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.

 

 

 

Please use plain text.
Contributor
dachmt
Posts: 25
Registered: ‎04-16-2010

Re: Read .properties file

Exactly RexDoug.

 

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!

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008

Re: Read .properties file

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?

 

Please use plain text.