I was wondering, can I group properties in my property file? This is content of my property file:
dbpassword=password
database=localhost
dbuser=mkyong
I want to add to dbpassword more then 1 password. Can I do it?
I was wondering, can I group properties in my property file? This is content of my property file:
dbpassword=password
database=localhost
dbuser=mkyong
I want to add to dbpassword more then 1 password. Can I do it?
Typically you'd do this with some sort of manual "nesting":
foo.dbpassword=password
foo.database=localhost
foo.dbuser=mkyong
bar.dbpassword=...
...
But to be honest, by the time you've got a hierarchy, you should at least consider using a more naturally-hierarchical file format - XML springs to mind.
With a simple Properties file, you'd have to use
pwd1
, pwd2
, etc. or mybd1.pwd
, mybd2.pwd
, etc.)"mypass1 anotherpass"
)Supposing you use the second scheme, you may be interested by String splitting to extract the different passwords.
In property file,
dbpassword=password1,password2
In java file,
String[] dbpasswords = properties.getProperty("dbpassword").split(",");
You should reference in Multiple values in java.util.Properties
You can store your properties as an XML file. It will be smth like:
<props>
<database>
<name>name1</name>
<dbpass>pass1</dbpass>
<dbuser>user1</dbuser>
</database>
<database>
<name>name2</name>
<dbpass>pass2</dbpass>
<dbuser>user2</dbuser>
</database>
</props>