• Post Reply Bookmark Topic Watch Topic
  • New Topic

Values in a Properties File  RSS feed

 
Fred Victa
Ranch Hand
Posts: 206
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
 
Jeff Verdegan
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.
 
Daniel Val
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
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!