J2SE API读取Properties文件的六种方法 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-18
assert (JProperties.class.equals(new JProperties().getClass())); in = JProperties.class.getResourceAsStream(name); assert (in != null); p.load(in); //return new JProperties().getClass().getResourceAsStream(name); } else if (type == BY_CLASSLOADER) { assert (JProperties.class.getClassLoader().equals( new JProperties().getClass().getClassLoader())); in = JProperties.class.getClassLoader().getResourceAsStream(name); assert (in != null); p.load(in); //return new JProperties().getClass(). getClassLoader().getResourceAsStream(name); } else if (type == BY_SYSTEM_CLASSLOADER) { in = ClassLoader.getSystemResourceAsStream(name); assert (in != null); p.load(in); } if (in != null) { in.close(); } return p; } // ---------------------------------------------- servlet used /* public static Properties loadProperties( ServletContext context, String path) throws IOException { assert (context != null); InputStream in = context.getResourceAsStream(path); assert (in != null); Properties p = new Properties(); p.load(in); in.close(); return p; } */ // ---------------------------------------------- support class /** * ResourceBundle Adapter class. */ public static class ResourceBundleAdapter extends Properties { public ResourceBundleAdapter(ResourceBundle rb) { assert (rb instanceof java.util.PropertyResourceBundle); this.rb = rb; java.util.Enumeration e = rb.getKeys(); while (e.hasMoreElements()) { Object o = e.nextElement(); this.put(o, rb.getObject((String) o)); } } private ResourceBundle rb = null; public ResourceBundle getBundle(String baseName) { return ResourceBundle.getBundle(baseName); } public ResourceBundle getBundle(String baseName, Locale locale) { return ResourceBundle.getBundle(baseName, locale); } public ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader) { return ResourceBundle.getBundle(baseName, locale, loader); } public Enumeration<String> getKeys() { return rb.getKeys(); } public Locale getLocale() { return rb.getLocale(); } public Object getObject(String key) { return rb.getObject(key); } public String getString(String key) { return rb.getString(key); } public String[] getStringArray(String key) { return rb.getStringArray(key); } protected Object handleGetObject(String key) { return ((Proper |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于J2SE API读取Properties文件的六种方法 - 编程入门网的所有评论