package com.ui.version.config; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; public class Config { private static Logger log = Logger.getLogger(Config.class.getName()); private static final String fileName = "xiu-ui.properties"; private static final String fileName2 = "com/ui/version/resources/xiu-ui.properties"; private static Properties properties = new Properties();; static{ boolean ready = false; InputStream is = Config.class.getClassLoader().getResourceAsStream(fileName); if(is != null){ try { properties.load(is); ready = true; log.log(Level.INFO, "加载classpath:"+fileName+"成功!"); } catch (IOException e) { log.log(Level.WARNING, "加载classpath:"+fileName+"失败", e); } } if(!ready){ is = Config.class.getClassLoader().getResourceAsStream(fileName2); if(is != null){ try { properties.load(is); ready = true; log.log(Level.INFO, "加载classpath:"+fileName2+"成功!"); } catch (IOException e) { log.log(Level.WARNING, "加载classpath:"+fileName2+"失败", e); } } } if(!ready){ log.log(Level.SEVERE, "未能找到资源,请将"+fileName+"文件放到classes目录下"); } } public static String getConfigValue(String key){ return properties.getProperty(key,null); } public static Properties getProperties(){ return properties; } }
读取WEB-INF/classes目录下文件,及读取其key-value
猜你喜欢
转载自dengli19881102.iteye.com/blog/1738162
今日推荐
周排行