|
|
|
| Web Hosting Guide |
![]() ![]() |
Use Of Xml Properties File For One Key - Multiple Value Mapping, - should I use some other Class? |
May 12 2008, 05:54 AM
Post
#1
|
|
|
Cosmic Overlord Group: Members Posts: 571 Joined: 26-November 05 From: Denver, Colorado, US Member No.: 9,811 myCENTs:45.66 |
Here is a situation I have encountered. I know I can write a custom code to get the job done, but I was wondering if the java.util.Properties class (or something else) had this inbuilt and I was missing it in the documentation.
Situation: Need to load from a file, a set of values (mutliple values) for an associated single key. To illustrate, here is an example: propfile.properties CODE <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <entry key="fooA">barA1</entry> <entry key="fooA">barA2</entry> <entry key="fooB">barB1</entry> </properties> The fooB=barB1 is a trivial case in implementing using the Properties class. But what about the multiple case - fooA=[barA1,barA2] ? How do I get them into a HashMap or something? Here is a independent code snippet that shows my attempt. It shows the trivial case without any problem. PropPlay.java CODE import java.util.Properties; import java.io.FileInputStream; public class PropPlay { /** * @param args */ public static void main(String[] args) { System.out.println(" --------------------------------------- "); System.out.println(" - This is a Java Properties file test - "); System.out.println(" --------------------------------------- \n"); try { System.out.println("Loading cfg/propfile.properties"); FileInputStream fis = new FileInputStream("cfg/propfile.properties"); System.out.println("...loaded.\n"); System.out.println("Loading to internal Properties object"); Properties prop = new Properties(); prop.loadFromXML(fis); System.out.println("...loaded.\n"); System.out.println("Here are the properties:"); prop.list(System.out); System.out.println("\nGetting properties for fooA: "); System.out.println(prop.getProperty("fooA")); } catch (Exception e) { e.printStackTrace(); System.out.println("Bailing out!!"); } } } Output: CODE --------------------------------------- - This is a Java Properties file test - --------------------------------------- Loading cfg/propfile.properties ...loaded. Loading to internal Properties object ...loaded. Here are the properties: -- listing properties -- fooA=barA2 fooB=barB1 Getting properties for fooA: barA2 The one key - multiple values obviously does not work as intended. Any idea how I can get it into a HashMap or some object like that? This post has been edited by Vyoma: May 12 2008, 05:57 AM |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
1 | ssp2010 | 6 | Today, 07:47 PM Last post by: 8ennett |
|||
![]() |
18 | vicky99 | 7,570 | 24th February 2010 - 08:16 PM Last post by: iG-ivmai |
|||
![]() |
8 | Spencer | 726 | 23rd February 2010 - 12:02 PM Last post by: iG-Nas Nijjar |
|||
![]() |
5 | jackpinerepublic | 4,388 | 19th February 2010 - 02:04 AM Last post by: iG-Simon Varley |
|||
![]() |
17 | rapco | 9,921 | 12th February 2010 - 06:48 AM Last post by: iG-Sanjaya |
|||
![]() |
15 | PureHeart | 11,903 | 10th February 2010 - 08:02 PM Last post by: iG-khadeer |
|||
![]() |
14 | jedipi | 7,764 | 10th February 2010 - 05:47 PM Last post by: iG-keith |
|||
![]() |
12 | Nqon | 4,586 | 9th February 2010 - 02:46 PM Last post by: iG- |
|||
![]() |
22 | muazamali | 8,896 | 9th February 2010 - 04:18 AM Last post by: topboys |
|||
![]() |
14 | bob3695 | 10,093 | 8th February 2010 - 09:19 PM Last post by: iG-Manish Patel |
|||
![]() |
32 | Jackel | 8,680 | 7th February 2010 - 09:09 AM Last post by: iG-LostOnline |
|||
![]() |
1 | evought | 171 | 5th February 2010 - 10:04 PM Last post by: dangerdan |
|||
![]() |
5 | Jeigh | 3,635 | 3rd February 2010 - 07:16 PM Last post by: iG-Juan |
|||
![]() |
0 | 8ennett | 164 | 29th January 2010 - 03:57 PM Last post by: 8ennett |
|||
![]() |
2 | kanade | 729 | 28th January 2010 - 01:06 PM Last post by: iG-pankaj |
|||
|
Lo-Fi Version | Time is now: 19th March 2010 - 10:17 PM |
© 2010 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



May 12 2008, 05:54 AM






