JAVA项目读取配置文件【相对路径】
程序员文章站
2022-05-10 09:18:25
...
package com.*.*.web.utils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class CacheAgreementInfo {
@SuppressWarnings("unused")
public static Map<String, String> CacheAgreementInfo() throws Exception {
Map<String, String> agreementMap = new HashMap<String, String>();
Properties props = new Properties();
try {
props=PropertiesLoaderUtils.loadAllProperties("*.properties");
for(Object key:props.keySet()){
String valueIs = (String)props.get(key);
String value=new String(valueIs.getBytes("ISO8859-1"),"UTF-8");
agreementMap.put((String) key, value);
}
} catch (IOException e) {
throw new Exception("读取协议文件失败");
}
return agreementMap;
}
public static void main(String[] args) throws Exception {
CacheAgreementInfo();
}
}
*交流分享,杜绝私藏。崇尚开源
上一篇: HTML相对路径和绝对路径