public class LoadProperty {
    private static LoadProperty _instance = null;
    private Properties props = new Properties();    private LoadProperty() {
        init();
    }    public static LoadProperty instance(){
        if (_instance==null){
            _instance = new LoadProperty();
        }
        return _instance;
    }    public Properties getProperty(){
        return props;
    }    /**
     * load DBSettings.properties file property into props
     */
    private void init(){
        //locad the file
        InputStream is = getClass().getResourceAsStream("/config.properties");
//        System.out.println("inputStream="+is);
        try {
            props.load(is);
        } catch (IOException e) {
            System.err.println("read DBSettings.properties error");
        }    }
}

解决方案 »

  1.   

    ResourceBundle rb=ResourceBundle.getBundle("你的文件");
     String dbjndi = rb.getString("dbjndi");文件的内容如下:
    dbjndi = dhccrmjndi打印出String dbjndi 的值就是dhccrmjndi了!
      

  2.   

    有没有那种将config.properties配置文件放在WEB-INF/classes路径下,javabean在/cn/com/下
    既:/WEB-INF/classes/config.properties,由/cn/com/javabean中访问该配置文件,运行环境为HP-UNIX,WEBLOGIC
      

  3.   

    ResourceBundle rb=ResourceBundle.getBundle("../../config.properties");
      

  4.   

    用configFile.load(getClass().getResourceAsStream("config.properties"));
    与configFile.load(getClass().getClassLoader().getResourceAsStream(
             "config.properties"));
    有什么区别呢???