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 writing a wrapper class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writing a wrapper class" Watch "writing a wrapper class" New topic

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:

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);
// accessor methods - setter methods
private void setWindowWidth(){width = Integer.parseInt(props.getProperty("WIDTH"));}
}//end of class
My question is: Ami I on the right track here?
2b | | !2b
[This message has been edited by Peter Simard (edited November 08, 2001).]

PAS<br /><br />2b || !2b
David O'Meara

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?
I agree. Here's the link:
subject: writing a wrapper class
It's not a secret anymore!