import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropsUtils {
private Properties props;
public PropsUtils(String src){
props = new Properties();
InputStream in = null;
try {
in = new FileInputStream(new File(src));
props.load(in);
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public Object getBean() throws Exception {
Object obj = Class.forName(props.getProperty("clazzName"))
.newInstance();
return obj;
}
public static void main(String[] args) throws Exception {
DemoClass dc =(DemoClass)new PropsUtils("src/clazz.properties").getBean();
dc.run();
}
}
//配置文件中 clazzName = cn.itcast.heima.DemoClass |