Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2005

Tip: Looking for answers? Try searching our database.

using Properties files properly

Thread view: 
antoine - 23 Aug 2005 04:32 GMT
Hello,

I was not very happy with my INI file handling and finally decided to
migrate to the more common "properties" file as defined in JDK (I'm
using 1.4)

here's the thing: I have a long list of properties, that I grouped like
that:

item1.prop1
item1.prop2
item1.prop3
item1.prop4

item2.prop1
item2.prop2
item2.prop3
item2.prop4

everything works OK, it loads, saves, and my app works. however there
are times when I need to access the properties file and modify it
manually (using a text editor). that's when I realized that all
properties were "reorganized" pretty randomly in my file:

item2.prop3
item1.prop2
item2.prop4
item1.prop4
item1.prop3
item2.prop1
item1.prop1
item2.prop2

it becomes very complicated to find what I'm looking for...
is there a simple way to make things better ?
Roedy Green - 23 Aug 2005 07:13 GMT
>it becomes very complicated to find what I'm looking for...
>is there a simple way to make things better ?

The problem is Properties is a HashMap/Hashtable (I forget which).
HashMaps don't have an order.  They use the effective random ordering
of hash to slot number, i.e. hashCode/length hasharray.

What can you do about it?

1. Write your own save method that does a sort then save.

2. use the sort feature of your text editor when you set out to edit
the file.

3. write your own properties class that has the features you want. I
wrote one that allows multiple values per key.  You are welcome to it.
Just send me an email with the subject MultiProperties.

4. Use the Preferences class.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com

Andrew Thompson - 23 Aug 2005 07:26 GMT
> ..there
> are times when I need to access the properties file and modify it
> manually

One alternative is to write a little Java based editor
to load and save the properties.  You could provide
a sorted list of property names on the left, and a single
text area on the right to edit the value of the property.

Easy peasy..

> ..(using a text editor)

Ughh.. Write an editor.  A couple of hours spent writing
an editor now, might save you dozens of hours over the
long run.

HTH

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"..a government for hire and a combat site."
R.E.M. 'It's The End Of The World As We Know It (And I Feel Fine)'



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.