Author:趙志乾
Date:2024-07-11
Declaration:All Right Reserved!!!
1. 簡介
? ? ? ? .properties文件是一種簡單的文本文件,用于存儲鍵值對,其每個鍵值對占一行,且鍵和值之間用等號分割。Java提供了java.util.Properties類來加載和讀取.properties文件。
2. 代碼示例
public static Properties loadProperties(String filePath) {InputStream inputStream = null;try {inputStream = new FileInputStream(filePath);Properties properties = new Properties();properties.load(inputStream);return properties;} catch (Exception ex) {log.error("加載配置文件失敗! ex=", ex);return new Properties();} finally {if (inputStream != null) {try {inputStream.close();} catch (IOException e) {log.error("關閉配置文件失敗! ex=", e);}}}
}