wang
2024-04-03 b0cd8e56e79637407ff32bd559eab896101d887c
UnLoadGlassModule/src/main/java/com/mes/tools/Configuration.java
@@ -5,11 +5,24 @@
import java.io.InputStream;
import java.util.Properties;
// Configuration 类用于加载配置文件并提供访问配置项的方法。
/**
 * @author SNG-012
 *
 *  Configuration 类用于加载配置文件并提供访问配置项的方法。
 */
public class Configuration {
    private Properties properties; // Properties 对象,用于存储配置文件中的键值对。
    // 构造函数,根据传入的文件名加载配置文件。
    /**
     * // Properties 对象,用于存储配置文件中的键值对。
     */
    private Properties properties;
    /**
     * @param fileName
     * @throws IOException
     *     // 构造函数,根据传入的文件名加载配置文件。
     */
    public Configuration(String fileName) throws IOException {
        // 使用类加载器获取资源文件的输入流。
        InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName);
@@ -17,11 +30,18 @@
        if (inputStream == null) {
            throw new FileNotFoundException("Property file '" + fileName + "' not found in the classpath");
        }
        properties = new Properties(); // 实例化Properties对象。
        properties.load(inputStream); // 从输入流加载配置项。
        // 实例化Properties对象。
        properties = new Properties();
        // 从输入流加载配置项。
        properties.load(inputStream);
    }
    // 根据配置项的键获取其对应的值。
    /**
     * @param key
     * @return
     *     // 根据配置项的键获取其对应的值。
     */
    public String getProperty(String key) {
        return properties.getProperty(key);
    }