急!高手帮个啦! 那们兄台知道怎么从配置文件中加载类,然用用map中的key存类名,value存实例 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以从配置文件中读取相关的类,然后利用Class.forName("..类");将其放入Map中 public Properties getProperty() { Properties pro = new Properties(); InputStream in = null; try { in = getClass().getResourceAsStream("class.propertys"); pro.load(in); } catch (Exception e) { } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } return pro; } public void test() throws InstantiationException, IllegalAccessException, ClassNotFoundException { Map<String, Object> map = new HashMap<String, Object>(); Properties p = getProperty(); Enumeration keys = p.keys(); while(keys.hasMoreElements()) { String key = (String)keys.nextElement(); String className = p.getProperty(key); Object obj = Class.forName(className).newInstance(); map.put(key, obj); } } Eclipse RCP深入浅出电子书 如何计算出两个日期之间所间隔总年 如何通过JAVA 实现屏蔽键盘快捷键? java 文件读写问题 双击可执行Jar文件找不到main---虽然我指定了<manifest> 求助TUXEDO在AIX系统下的开发 这个关于JSlider的异常是什么意思? 谁有Effective Java 英文电子版?高分相赠 有两个问题请教大家!!! 谁来推荐一本关于学习JBUILDER的参考书! 江湖告急!高手帮个啦! JAVA卜能用了?这种情况该怎么办?
public Properties getProperty() {
Properties pro = new Properties();
InputStream in = null;
try {
in = getClass().getResourceAsStream("class.propertys");
pro.load(in);
} catch (Exception e) { } finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
return pro;
} public void test() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Map<String, Object> map = new HashMap<String, Object>();
Properties p = getProperty();
Enumeration keys = p.keys();
while(keys.hasMoreElements()) {
String key = (String)keys.nextElement();
String className = p.getProperty(key);
Object obj = Class.forName(className).newInstance();
map.put(key, obj);
}
}