快速业务通道

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 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号