Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Properties.getProperty()

Reply
Thread Tools

Properties.getProperty()

 
 
Anuradha
Guest
Posts: n/a
 
      10-22-2003
Hi,

I am just trying to read a property file but would like to know if
getProperty would return by searching ignorecase; if not how to
implement.

For example

in my code

prop.getProperty( "db2.server" ) returns 192.24.43.56

while

prop.getProperty( "DB2.server" ) returns null

while i would like to return 192.24.43.56


in my property file entry is as below

db2.server = 192.24.43.56

Any insights is appreciated.

Thanks,
Anu
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      10-22-2003
Anuradha wrote:
> I am just trying to read a property file but would like to know if
> getProperty would return by searching ignorecase; if not how to
> implement.
>
> For example
>
> in my code
>
> prop.getProperty( "db2.server" ) returns 192.24.43.56
>
> while
>
> prop.getProperty( "DB2.server" ) returns null
>
> while i would like to return 192.24.43.56
>
>
> in my property file entry is as below
>
> db2.server = 192.24.43.56


The easy answer is that properties are case sensitive, so know and use
the correct case.

Properties objects are Maps where the keys and values are all supposed
to be Strings. Java Strings are case-sensitive, so you won't get what
you want without some fiddling. You will have to either add extra
entries to your Properties object or replace existing ones with
differently capitalized versions.

You could also create a case-insensitive string class, with suitable
hashCode and equals methods, and construct a HashMap with keys of your
new class corresponding to values from the original properties. You
would then need to look them up with the use of instances of your
case-insensitive string class, but you could hide that behind a method
that accepted regular Strings. This is a good, general solution to the
problem, but I'm still not convinced that the problem is one that you
need to solve.


John Bollinger


 
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




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