This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Spring and the fly likes Read key and value from properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Read key and value from properties file" Watch "Read key and value from properties file" New topic
Author

Read key and value from properties file

Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
Hi all,
How can I read multiple key and value from properties file.
can any one help me please

Thanks in advance
Abhay
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

If you want it as a bean to inject into your classes. you can use the util namespace and

<util:properties id="myProps" location="location of .properties file"/>

Or do you just mean myPropertiesInstance.getProperty("propertyNameHere");

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
Thanks for your replay. It is not solving my problem-

My properties file is like -

P1 = com.tt.example1
p2 = com.tt.example2
p3 = com.tt.example3.

here com.tt.example1,example2,example3 is java class. How can I read all value at a time using spring configuration file. It should not be hard code.\

Thanks in advance
Abhay
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

Abhay Choubey wrote:Thanks for your replay. It is not solving my problem-

My properties file is like -

P1 = com.tt.example1
p2 = com.tt.example2
p3 = com.tt.example3.

here com.tt.example1,example2,example3 is java class. How can I read all value at a time using spring configuration file. It should not be hard code.\

Thanks in advance
Abhay


My question is still the same? How exactly do you want to use the values, It makes a big difference in the answer.

Look at the PropertyPlaceholderConfigurer in the Spring Framework documentation to see if that is what you need. Are you using Spring 3.x, if so, then I recommend reading about the Spring Expresssion language in the Spring Framework documentation.

Thanks

Mark

 
Don't get me started about those stupid light bulbs.
 
subject: Read key and value from properties file