This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Reading a property file in the controller

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In my application i want to read a property file in my controller class.
The structure of property file looks like this:
######## messages.properties ##########
exit=http://www.way2bet.com.au
show=true
message=Did you know Timbuktu was in Mali?
footer=www.way2play.com
congrats=Congratulations! You have not achieved Leaderboard status
fail=Unlucky! Your score was not good enough!
round.complete=Sample text to appear on Round Complete screen


I need to generate an xml file based on the above property file.
The reading of the property file should be dynamic i.e. If i want to add some new property the controller logic should not change.

Please Help. A code snippet will be a big help.
Thanks.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Spring an easy way to do this from the file system is:


or from the classpath:


Either technique can of course throw an IOException but you don't have to manage the resource yourself.


See the Javadoc for more details.

[ August 07, 2007: Message edited by: Ken Krebs ]
[ August 07, 2007: Message edited by: Ken Krebs ]
 
Rajesh Rathod
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok let me check whether it will work or not. Thanks a lot
 
Rajesh Rathod
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a one more way to load the property file into the application
i.e ResourceBundle objects = ResourceBundle.getBundle("file_path");

I think this is more easiest way to achieve the desire functionality.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If instead of loading the properties in code, you want to inject them during configuration, PropertyPlaceholderConfigurer is a good option.

See PropertyPlaceHolderConfigurer

Cheers.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also check this....

Properties prop = new Properties();
prop.load(new FileInputStream(filePath));

Regards
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!