Reading all related keys from a properties file

I have in my propeties file, keys the following way:

FIRST_DATASOURCE=COM.XYZ.ABCSERVER.JDBC1

SECOND_DATASOURCE=COM.ABC.SERVER2.JDBC1

FIRST_DATASOURCE=COM.123.SERVER3.JDBC3

What is the solution to read all the keys wit _DATASOURCE and return as a string array?

Thanks in advance.

[316 byte] By [KSNSa] at [2007-11-27 0:50:38]
# 1
Implement a custom property reader.
CeciNEstPasUnProgrammeura at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 2
I do not understand your high level suggestion. can you Pl exaplin in detail?
KSNSa at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 3
> What is the solution to read all the keys wit> _DATASOURCE What you posted isn't a valid property file. Two keys can't have the same name. Kaj
kajbja at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 4
> I do not understand your high level suggestion. can> you Pl exaplin in detail?In short. You can't use java.util.Properties if your data looks like that.Kaj
kajbja at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 5
> I do not understand your high level suggestion. can> you Pl exaplin in detail?In detail: write a class that does what you want. A Hashmap and a few ArrayLists might help for starters.
CeciNEstPasUnProgrammeura at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 6

hI KAJBJ

sORRY FOR the typo error. The code is as follows:

FIRST_DATASOURCE=COM.XYZ.ABCSERVER.JDBC1

SECOND_DATASOURCE=COM.ABC.SERVER2.JDBC2

THIRD_DATASOURCE=COM.123.SERVER3.JDBC3

Clarification:

Is there any method available in ResourceBundle class to read the keys and get a String[ ]?

Thanks

KSNSa at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 7
> Clarification:> Is there any method available in ResourceBundle class> to read the keys and get a String[ ]?No, read the data, add it to e.g an ArrayList<String>, and call toArray when you are done reading.Kaj
kajbja at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 8
Hi KajbjThanks for the reply.reading data..?What is your idea to read and place in an array list. Can you give a sample code?Thanks
KSNSa at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 9
ArrayList<String> tmp = new ArrayList<String>();result.add(theProperties.getProperty(key1));result.add(theProperties.getProperty(key2));String[] result = tmp.toArray(new String[tmp.size()]);
kajbja at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 10
Thanks kajbj..The problem here is the datasources are added from time to time and the program should pick-up dynamically.If I hardcode for the existing available datasources, how can it handle for the future?Appreciate your thoughts.
KSNSa at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 11
> Appreciate your thoughts.Depends on what more you have in that file. You can get all keys, do a substring search and see if they match a certain pattern, then get the values for those that match.Kaj
kajbja at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...
# 12

> Thanks kajbj..

>

> The problem here is the datasources are added from

> time to time and the program should pick-up

> dynamically.

>

> If I hardcode for the existing available datasources,

> how can it handle for the future?

>

> Appreciate your thoughts.

Many answer can be found by reading API

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#propertyNames()

rym82a at 2007-7-11 23:20:51 > top of Java-index,Java Essentials,Java Programming...