aspose file tools*
The moose likes Beginning Java and the fly likes writing a wrapper class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writing a wrapper class" Watch "writing a wrapper class" New topic
Author

writing a wrapper class

Peter Simard
Ranch Hand

Joined: Oct 31, 2001
Posts: 54
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).]


PAS<br />peter@panvox.net<br />2b || !2b
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing a wrapper class