首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

构建自个儿的commons

2012-06-30 
构建自己的commonsweb项目中加载配置信息,废话不说,直接上代码?ClassLoader loader Thread.currentThrea

构建自己的commons

web项目中加载配置信息,废话不说,直接上代码

?

ClassLoader loader = Thread.currentThread().getContextClassLoader();URL url = null;String propertyName = "url.properties";if (loader instanceof URLClassLoader) {URLClassLoader ucl = (URLClassLoader) loader;url = ucl.findResource(propertyName);}if (url == null) {url = loader.getResource(propertyName);}if (url == null) {System.out.println("No properties file: " + propertyName + " found");} else {Properties bundle = new Properties();InputStream is = url.openStream();if (is != null) {bundle.load(is);is.close();} else {throw new IOException("Properties file " + propertyName + " not available");}Enumeration<?> propertyNames = bundle.propertyNames();while (propertyNames.hasMoreElements()) {String key = (String) propertyNames.nextElement();String value = bundle.getProperty(key);groupListMap.put(key, Arrays.asList(value.split(",")));System.out.print("Loaded user " + key + ":");for (String role : groupListMap.get(key)) {System.out.print(" " + role);}System.out.println();}}
?

热点排行