File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Loading Properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loading Properties file" Watch "Loading Properties file" New topic

Loading Properties file

Shruthi Babu
Ranch Hand

Joined: May 04, 2007
Posts: 54
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.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

You don't need to make them final, just immutable (unchangeable). Try something like this?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Shruthi Babu
Ranch Hand

Joined: May 04, 2007
Posts: 54
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?
I agree. Here's the link:
subject: Loading Properties file
It's not a secret anymore!