public class ProjectConfig {
private static final Logger log = LoggerFactory.getLogger(ProjectConfig.class);
private static String configFile = "/appstore.properties";
private static Properties prop = new Properties();
static {
InputStream is = ProjectConfig.class.getResourceAsStream(configFile);
BufferedReader bf = new BufferedReader(new InputStreamReader(is));
if (is == null) {
log.error(configFile + "文件不存在,请检查");
} else {
try {
prop.load(bf);
} catch (Exception e) {
log.error("读取" + configFile + "出错:" + e.getMessage());
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
log.error("关闭IO流出错:" + e.getMessage());
}
}
}
}
}
public static String getProperty(String key) {
return prop.getProperty(key);
}
public static void main(String[] args) {
String athena_config_test = ProjectConfig.getProperty("id");
System.out.print(athena_config_test);
}
}
获取properties文件工具类
最新推荐文章于 2023-09-16 13:04:07 发布