• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is is possible to read values from a properties file but have those variables be static?

 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a .properties file which i will be reading in a class. I need to get the values from the properties file as static ,Is is possible to read values from a properties file but have those variables be static? How can i do it.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just declare your Properties variable as a static variable. As such, it would probably be best to load your the file in the a static initializer block:



Alternatively, you could have a static method that loads the properties file and then in your constructor do a lzay init of the properties file:



 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Mark, will be trying that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic