aspose file tools*
The moose likes Java Micro Edition and the fly likes reading properties files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "reading properties files" Watch "reading properties files" New topic
Author

reading properties files

Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
Hi...

I want to keep some often changed information such List item name, etc in a properties file...


This seems to be a better option than touching the JAD file...

Can anyone suggest me a way to access this file that resides in the jar itself...

any links to codes will be appreciated...

thanks


Theepan Thevathasan
SCJP 1.4, SCWCD 1.4, SCMAD 1.0 SCBCD 1.3, MCP(.Net Frm 2.0 App Dev Fdn)
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Hi Theepan,

I think you can use InputStream class for this purpose.

Regards,
Arnab
Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
hi...

ok...then how could i get the name/value pairs...

i havent done reading text files like properties files before..

are there any code urls for this
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
You can use this code to parse name/value pair from a property file contained within a midlet Jar file.

http://worlddeveloper.org/www/forumtopicview.html?fid=42&categoryId=36&fpn=0

Strip out the code that you do not need.

The usage is pretty simple.



The property file should be located in "/config"

Example:

/config/myappproperties.properties


Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Thanks for the link Rashid. It is interesting.

So if I understand you correctly, you are suggesting reading form RMS. Which means extracting the property file from the jar file and storing in the RMS before reading it.

Is it correct ?

Regards,
Arnab
Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
Rashid,

Thanks for the link...

It was an excellent utility...

Great Job...
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Hi Theepan, Rashid

So are we thinking of retrieving the data from JAR, storing it in RMS and then accessing it ?

Arnab
Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
Yes..

That method has been opted to avoid reading from the file everytime...

Reading from thereafter from the RMS is comparatively faster..
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
Sorry for the late response, I am traveling at the moment. The utility gives you the option for both mechanisms.

Values in the RMS override values from the file. You can use the values in the files as defaults, and allow the user to override the defaults through a settings screen.

For example, the properties file may store the default background color. The user can be given the option to override the background color. The new value on the background color would be saved in the RMS on exit and loaded during startup.

To go a step further, some of my applications required a mechanism for overriding application settings from the server. a server could push overrides or the client could download overrides for the defaults programmatically.

This is completely optional of course. If you do not need this type of functionality you could strip out the code.
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
Forgot to add, the last note about the save is important. The current write() method deletes the RMS and writes the in-memory hash. You could optimize this method to only write the values that have changed.
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
ok... now I am a bit confused... the original question was how to read the file from the jar...

If we are trying to read from the RMS, then there has to be a mechanism to transfer the file which is the jar to RMS location for future access..

Isn't this correct ?
Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
Sen...

In fact her is not trying to save the file as it is in the RMS...

Instead reading the key=value pairs and puts them to the RMS...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading properties files