public class PropertiesUtils {
private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
public static final Properties PRODUCER_PROP = PropertiesUtils.getProducerProps();
//软件安装目录
private static final String USER_DIR = System.getProperty("user.dir");
//配置文件目录
private static final String CONF_PATH = USER_DIR + File.separator + "conf" + File.separator;
/**
* 获取proterties
* * @param fileName 配置文件名称
* @return proterties
*/
private static Properties getProperties(String fileName) {
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(CONF_PATH + fileName));
} catch (FileNotFoundException e) {
logger.error(e.getMessage(), e);
}
Properties properties = new Properties();
try {
logger.trace("start loading file {} ",fileName);
properties.load(in);
logger.trace("load file {} success",fileName);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return properties;
}
/**
* 获取producer 的配置
*
* @return Properties
*/
private static Properties getProducerProps() {
return getProperties("producer.proterties");
}
public static void main(String[] args) {
System.out.println(USER_DIR);
System.out.println(CONF_PATH);
System.out.println(LIKEV_KAFKA_PROP);
}
}
以上代码有问题么?
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于