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