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
热度:402 发布时间:2012-12-17 09:31:40.0
相关解决方案
- [求助]C:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes
- 让IE6支持伪种(Pseudo-classes)
- 犀牛书第五版读书笔记――Chapter 9. Classes, Constructors, and Prototypes(第二一部分)
- 犀牛书第五版读书笔记――Chapter 9. Classes, Constructors, and Prototypes(第部分)
- 伪种(Pseudo-Classes)&伪对象(Pseudo-Elements)详解
- 犀牛书札记:(11)Classes, Constructors and Prototypes
- TIJ英文原版图书阅读之旅——Chapter Seven:Reusing Classes
- No relevant classes found. No output generated.解决方法
- 求指教The following classes could not be found: - DatePicker解决思路
- Part 32 Abstract classes in c
- 犀牛书笔记:(11)Classes, Constructors and Prototypes
- Enhancing custom classes 优化自定义类
- Duplicate class com.alipay.a.a.a found in modules classes.jar (:alipaySdk-15.6.2-20190416165036:) an
- The following classes could not be found - EditText (Change to android.widget.EditText, Fix Build Pa
- 【more effective c++读书笔记】【第5章】技术(6)——Proxy classes(代理类)
- Android EventBus 报错 xxx and its super classes have no public methods with the @Subscribe annotation
- Please provide compiled classes of your project with sonar.java.binaries property sonarqube扫描报错
- 安装过程中会出现无法将数值URL Protocol写入键\Software\Classes\XXX
- Iterator Classes (迭代器类)
- 编译错误处理noproguard.classes-with-local.dex已杀死
- POSIX character classes (US-ASCII Only)