package util; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * 获取配置文件信息 * * @author Carl * */ public final class GetProperties { private static Properties prop = null; static{ prop = new Properties(); //设置properties文件路径,以src为根路径(config.properties 处于src根目录下) InputStream in = GetProperties.class.getResourceAsStream("/config.properties"); try { prop.load(in); } catch (IOException e) { System.out.println("读取配置文件失败---->>>>----(/src/config.properties)"); e.printStackTrace(); } } /** * 根据传入的KEY获取配置文件中对应的值 * @param key * @return */ public static String getPropertieValue(String key){ String value = ""; value = prop.getProperty(key).trim(); return value; } }
时间: 2024-10-01 05:20:16