관리 메뉴

빛과소금(http://searcher.tistory.com)

java properties 클래스.. 본문

IT 세상/자바세상

java properties 클래스..

Michael 이현민 (지후지율아빠) 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);
    }

}

2 Comments
댓글쓰기 폼