• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to save data from a properties file and use that data as a value in a class field?  RSS feed

 
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I'm really stumped about this. From my Main class,   I use java.util.Properties to load a properties file and pass it to a method (setPropertyValues ()) in my CommonProperties class file.   I think I'm correct in saying that how I am doing this below , makes it where those values are only available to the "storeProp" object?  What I want to do is store the values from the properties file so they are available for use by other classes when I create a new CommonProperties object.


Can someone help with this?  I'm not sure where to begin.





 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have loadPropertiesFile() return Properties.
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You could have loadPropertiesFile() return Properties.


I want to be able to use the individual fields which are in CommonProperties class in other class files and have them provide the values from my properties file.  The loadPropertiesFile() method is in my Main class file.   

For Example

From a different class file.
CommonProperties example new CommonProperties ();
example.getAuthServer();

or
example.authServer;

And have authServer ( or getAuthServer() ) return the authorization-server value from ztb-ck.properties.
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bump.  Any suggestions on this?
 
Saloon Keeper
Posts: 4038
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use a library like http://commons.apache.org/proper/commons-configuration/ to assign values from properties to fields.
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:You could also use a library like http://commons.apache.org/proper/commons-configuration/ to assign values from properties to fields.


Thank You.  I'll check it out.

 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa Austin wrote:I want to be able to use the individual fields which are in CommonProperties class in other class files and have them provide the values from my properties file.  The loadPropertiesFile() method is in my Main class file.   

For Example

From a different class file.
CommonProperties example new CommonProperties ();
example.getAuthServer();

or
example.authServer;

And have authServer ( or getAuthServer() ) return the authorization-server value from ztb-ck.properties.

I think I would make the fields and the setProteryValues() method static.  Then you would set the property values like this: and from another file, access them like this:
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:
Lisa Austin wrote:I want to be able to use the individual fields which are in CommonProperties class in other class files and have them provide the values from my properties file.  The loadPropertiesFile() method is in my Main class file.   

For Example

From a different class file.
CommonProperties example new CommonProperties ();
example.getAuthServer();

or
example.authServer;

And have authServer ( or getAuthServer() ) return the authorization-server value from ztb-ck.properties.

I think I would make the fields and the setProteryValues() method static.  Then you would set the property values like this: and from another file, access them like this:


You are awesome.  Yes that worked.  I did that and OMG that's perfect. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!