package util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertiesUtil {
    private static Map<String, String> propertiesMap = new HashMap<>();

    static {
        try (InputStream input = PropertiesUtil.class.getClassLoader().getResourceAsStream("application.properties")) {
            if (input == null) {
                System.out.println("Sorry, unable to find config.properties");
                System.exit(1);
            }
            // 加载 properties 文件
            Properties properties = new Properties();
            properties.load(input);

            // 将 properties 文件内容存储到 Map 中
            for (String key : properties.stringPropertyNames()) {
                propertiesMap.put(key, properties.getProperty(key));
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    public static String ReadProperty(String propertyName) {
        return propertiesMap.get(propertyName);
    }
}