I am having the following problem. I have a configuration.properties
file that I would like to read inside my application. It is of the following form:
accountNames = account1, account2, account3
account1.userName = testUserName
account1.password = testUserPassword
account2.userName = secondTestUserName
account2.password = secondTestUserPassword
account2.userName = thirdTestUserName
account2.password = thirdTestUserPassword
How can I read all the accounts and store the pairs userName-userPassword in a HashMap
? As I see it, I have an array of 2-dimensional arrays. I am particulary interested in a code that accesses each attribute for an account.
EDIT: I have changed my configuration.properties
file to the following format:
userNames = testUserName, secondTestUserName, thirdTestUserName
testUserName = testUserPassword
secondTestUserName = secondTestUserPassword
thirdTestUserName = thirdTestUserPassword
And the code to handle this is the following:
properties.load(new FileInputStream(configFilePath));
for(String s : properties.getProperty("userNames").split(",")){
clientCredentials.put(s.trim(), properties.getProperty(s.trim()));
}
//test:
for(String s:clientCredentials.keySet()){
System.out.println("Key: "+s+" & value: "+clientCredentials.get(s));
}
Thank you for your help.