读取properties配置文件工具类
package com.cg.utils;
import java.io.InputStream;
import java.util.Properties;
import jdk.internal.org.objectweb.asm.commons.StaticInitMerger;
public class PropertyUtils {
private static Properties properties = new Properties();
static {
try {
InputStream inputStream = Properties.class.getResourceAsStream("/kafka.properties");
properties.load(inputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getKey(String key) {
return properties.getProperty(key);
}
public static Integer getInteger(String key) {
String value = properties.getProperty(key);
return null == value ? null : Integer.valueOf(value);
}
public static Boolean getBoolean(String key) {
String value = properties.getProperty(key);
return null == value ? null : Boolean.valueOf(value);
}
public static void main(String[] args) {
String topic = PropertyUtils.getKey("topic");
System.out.println(topic);
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/61c7b0d1a557b517c85a1930a38702e4.jpeg)