Properties.getProperty()

A

Anuradha

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
 
J

John C. Bollinger

Anuradha said:
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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top