상세 컨텐츠

본문 제목

java properties 클래스..

IT 세상/자바세상

by 이현민 (지후지율아빠) 2008. 9. 29. 11:25

본문

package kr.co.hmlee.common.filter.custom;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.ResourceBundle;

/**
 * Created by IntelliJ IDEA.
 * User: hmlee
 * Date: 2008. 9. 29
 * Time: 오전 11:17:02
 * To change this template use File | Settings | File Templates. */
public class Properties {
    public static String CONF_PATH="propertiesfile";
    public static Properties instance = null;

    private static Hashtable<String,String> h = null;

    private Properties(){
        h = new Hashtable<String,String>();
        init();
    }

    private static synchronized Properties getInstance(){
        if (instance == null) {
            instance = new Properties();
        }
        return instance;
    }

    public static String getProperties(String strKey){
        Properties proper = Properties.getInstance();
        return proper.getValue(strKey);
    }

    private void init() {
        ResourceBundle rb = ResourceBundle.getBundle(CONF_PATH);
        Enumeration keys = rb.getKeys();
        while (keys.hasMoreElements()){
            String key = (String)keys.nextElement();
            String value = rb.getString(key);
            h.put(key,value);
        }
    }

    private String getValue(String key){
        return h.get(key);
    }

}

반응형

관련글 더보기