Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing a wrapper class

 
Peter Simard
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a wrapper class which, when instantiated, will read program properties from a file and initialize the program on start up with the values.
some thing like this:

<code>
import java.io.*;
import java.util.Properties;
public class MyConfig
{
File file = new File("C:\\a_config_file.ini");
Properties props = new Properties();
public MyConfig()
{
FileInputStream f = new FileInputStream(file);
props.load(f);
props.close(f);
setWindowWidth();
}
// accessor methods - setter methods
private void setWindowWidth(){width = Integer.parseInt(props.getProperty("WIDTH"));}
}//end of class
</code>
My question is: Ami I on the right track here?
Thanks,
Pete
------------------
PAS
peter@panvox.net
2b | | !2b
[This message has been edited by Peter Simard (edited November 08, 2001).]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How much do you want?
There was a thread in the JDBC forum about 2 weeks ago where we built something similar (with source code).
I'd think about implementing the Singleton pattern so you can load the properties once and share them with your other classes, find a away to make it Thread-safe so that you aren't reading and changing the properties at the same time, and load the properties when the application is started (think about a static block).
Too much?
Dave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic