Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > using Properties files properly

Reply
Thread Tools

using Properties files properly

 
 
antoine
Guest
Posts: n/a
 
      08-23-2005
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 ?

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-23-2005
On 22 Aug 2005 20:32:59 -0700, "antoine" <>
wrote or quoted :

>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.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      08-23-2005
On 22 Aug 2005 20:32:59 -0700, antoine wrote:

> ..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

--
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)'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to copy all properties using properties.putAll() method. Sonal Java 3 12-07-2007 03:08 AM
CompositeControls: ViewState properties w/ Mapped properties probl =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?= ASP .Net 1 01-19-2006 09:19 AM
Making Custom Control Properties Visible in Visual Studio's Properties Palette Nathan Sokalski ASP .Net 0 10-17-2005 02:05 AM
More American Graffiti: Properly Framed, Properly Scored? Scot Gardner DVD Video 0 09-02-2003 02:28 AM
Documenting properties created by property() properly Brian Dam Pedersen Python 1 07-29-2003 11:58 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57