0

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?

Raimonds
  • 55
  • 5

4 Answers4

3

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
1

With a simple Properties file, you'd have to use

  • either more than one key (eg pwd1, pwd2, etc. or mybd1.pwd, mybd2.pwd, etc.)
  • a value with a separator and many paswords (eg "mypass1 anotherpass")

Supposing you use the second scheme, you may be interested by String splitting to extract the different passwords.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0

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

Community
  • 1
  • 1
swemon
  • 5,840
  • 4
  • 32
  • 54
0

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>
svz
  • 4,516
  • 11
  • 40
  • 66