Properties.getProperty()

Discussion in 'Java' started by Anuradha, Oct 22, 2003.

  1. Anuradha

    Anuradha Guest

    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
     
    Anuradha, Oct 22, 2003
    #1
    1. Advertising

  2. 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
     
    John C. Bollinger, Oct 22, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. iksrazal
    Replies:
    5
    Views:
    4,384
    Lothar Kimmeringer
    Aug 6, 2003
  2. Cheok Yan Cheng
    Replies:
    12
    Views:
    10,809
    John C. Bollinger
    Oct 5, 2004
  3. Mark Riordan
    Replies:
    0
    Views:
    1,093
    Mark Riordan
    Oct 14, 2004
  4. Stephan Melchior
    Replies:
    1
    Views:
    876
    Tor Iver Wilhelmsen
    Nov 21, 2004
  5. Marcus Reiter

    [jsp]: getProperty

    Marcus Reiter, Dec 26, 2004, in forum: Java
    Replies:
    18
    Views:
    3,649
    Ryan Stewart
    Dec 30, 2004
Loading...

Share This Page