Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Loading Properties file

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some values in my property files

for example

file_path = "file location"

I need to load these properties file and store them in java beans so that i can use them through out the porgram.

My concern is I need to make these values final as they are no gonna be changed. how to achieve this ?

Is this a good approach or is there a better way to do it.

Since i wanted to make it final the issue I am facing is

The properties file need to loaded initially before I assign it to the final class variables

need to do something like this

public static final String FILE_PATH = properties.getProperty("TXT_FILE_PATH) ;

how to load the properties before this class variables initialization.The file name for the porperties to be loaded need to be passed as parameter.

I was not able to use static block as i was not able to pass the parameter.
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Div,
You don't need to make them final, just immutable (unchangeable). Try something like this?

 
Shruthi Babu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply..

I need to pass the properties file name from some other class to this props class how can it be achieved? since we are calling a no-arg constructor?
 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic