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