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; } }