Results 1 to 3 of 3
  1. #1
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Exclamation Properties help needed

    Good evening everyone. The following is a problem i am trying to solve:

    When reading through an input file, i am populating my Properties object with newly discovered keys and values. All is well when keys are unique. The whole systems breaks down when keys are repeated.

    in my simplest terms, i would like to make the following work:

    Java Code:
    a.setProperty("apples", "green");
    a.setProperty("apples", "red");
    so that later i can reference both kinds of applies, green and red

    I tried this, but basically the same result

    Java Code:
    a.load(new StringReader("apples=red"));
    a.load(new StringReader("apples=green"));
    second key replaces the first key.

    I know that Properties does not enforce uniqueness by default - it is not a set. I have read files into and had to implement special logic to make sure my keys are unique.

    Ultimately i need to list through my properties object. Sequential list is fine, order does not matter.

    This would be an example of the type of listing i would like to do:

    Java Code:
    for (String hostname : targetPathToFile.stringPropertyNames()) {
        fe.copyFilesFromRemoteServer(hostname, targetPathToFile.getProperty(hostname), "/target/");
       logger.info(hostname + " -+- " + targetPathToFile.getProperty(hostname));
    }
    If you are looking for a real example of why this may be needed, imagine that you need to reference to discinct files both sitting on the same server separately.

    Thanks a bunch!

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Quote Originally Posted by mac View Post

    I know that Properties does not enforce uniqueness by default - it is not a set. I have read files into and had to implement special logic to make sure my keys are unique.
    java.util.Poperties inherits from Hashtable, so thats why you cannot use double keys.

    You can use some complex List<Map<K,V>> so you can put double values inside.
    But no properties file for you then, I guess you will have to write to some simple txt or csv file but will that suite your needs later...

    But one thing confuses me - you say that you have this logic for making keys unique?! Can you simply create different keys when values are double like :

    a.setProperty("apples_green", "green");
    a.setProperty("apples_red", "red");

    You can also try serialization i will send you easy example

    regards!

  3. #3
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

Similar Threads

  1. Properties
    By Winarto in forum XML
    Replies: 0
    Last Post: 08-29-2008, 03:32 PM
  2. properties help me please
    By Winarto in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-29-2008, 12:42 PM
  3. Getting .mp3 properties
    By Leprechaun in forum New To Java
    Replies: 1
    Last Post: 02-06-2008, 05:55 AM
  4. Replies: 0
    Last Post: 08-14-2007, 09:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •