读取.propertie后缀配置文件
1.配置静态加载
package com.hxl.utils.wx;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
/**
* 配置文件
* Created by hxl on 2019/9/5.
*/
public class ConfigUtil {
private static Properties props = new Properties();
static {
try {
props.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("wechat.properties"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String get(String key) {
return props.getProperty(key);
}
public static void setProps(Properties p) {
props = p;
}
}
2.调用
ConfigUtil.get("key键");