package com.emr.util;


import java.io.*;
import java.util.Properties;

public class PropertiesUtils {
    private static String fileName = "\\config\\config.properties";
    private static Properties props;

    synchronized static private void loadProps(){
        if (props==null) {
            props = new Properties();
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            try {
                props.load(loader.getResourceAsStream(fileName));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static String getProperty(String key){
        if(null == props) {
            loadProps();
        }
        return  props.getProperty(key);
    }

    public static String getProperty(String key, String defaultValue) {
        if (null == props) {
            loadProps();
        }
        return props.getProperty(key, defaultValue);
    }
}
