This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Values in a Properties File  RSS feed

 
Ranch Hand
Posts: 208
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a properties file in my Java application and I would like to have the property, event.name.alias, contain multiple values.

Would this be correct?

event.name.alias=myname1, myname2
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A java.util.Property always has a single value. If you want to interpret that value as multiple values separated by commas, you can, but you'll have to provide the code to split the single String up into multiple values based on your rules.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Fred Victa wrote:I have a properties file in my Java application and I would like to have the property, event.name.alias, contain multiple values.

Would this be correct?

event.name.alias=myname1, myname2



No you can't, it will return the string with commas inside.

Please think about using an xml...

D.
 
Author and ninkuma
Marshal
Posts: 66536
160
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML? Overkill for this simple requirement.
 
Daniel Val
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:XML? Overkill for this simple requirement.



True.

you can do like that

val_1=value for the first
val_2=value for teh second etc

Then you load the properties, then you get the iterator for the keys, then if the key "startsWith" val you get the value and add it to the list.

It works fine, but ensure you don't put by mistake a duplicate key val_something.

D
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!