Results 1 to 3 of 3
Thread: Properties help needed
- 03-15-2010, 11:22 PM #1
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:
so that later i can reference both kinds of applies, green and redJava Code:a.setProperty("apples", "green"); a.setProperty("apples", "red");
I tried this, but basically the same result
second key replaces the first key.Java Code:a.load(new StringReader("apples=red")); a.load(new StringReader("apples=green"));
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:
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.Java Code:for (String hostname : targetPathToFile.stringPropertyNames()) { fe.copyFilesFromRemoteServer(hostname, targetPathToFile.getProperty(hostname), "/target/"); logger.info(hostname + " -+- " + targetPathToFile.getProperty(hostname)); }
Thanks a bunch!
- 03-16-2010, 01:29 AM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
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!
- 03-16-2010, 02:28 AM #3
Similar Threads
-
Properties
By Winarto in forum XMLReplies: 0Last Post: 08-29-2008, 03:32 PM -
properties help me please
By Winarto in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-29-2008, 12:42 PM -
Getting .mp3 properties
By Leprechaun in forum New To JavaReplies: 1Last Post: 02-06-2008, 05:55 AM -
urgent help needed for [application-${environment}.properties]
By deepman in forum Advanced JavaReplies: 0Last Post: 08-14-2007, 09:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks