获取java中resoures文件夹的配置

 获取java中resoures文件夹的配置

工具类:

package com.asiainfo.c3.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public final class Config {
	private final static Logger LOGGER = LoggerFactory.getLogger(Config.class);
	private static Properties properties;
	
	private Config(){}
	
	static {
		try {
			// 初始化 properties文件
			properties = new Properties();
			String filePath = "conf/init.properties";
			InputStream in = new BufferedInputStream(Config.class.getClassLoader().getResourceAsStream(filePath));
			properties.load(in);
			in.close();
			
		} catch (IOException e) {
			LOGGER.error("读取配置信息出错!",e);
		}
	}

	public static String getObject(String prepKey) {
		prepKey = prepKey.trim();
		if (properties.containsKey(prepKey)) {
			return properties.getProperty(prepKey).trim();
		} else {
			return "";
		}
	}
	
	public static Integer getInt(String prepKey) {
		if (properties.containsKey(prepKey)) {
			return Integer.valueOf(properties.getProperty(prepKey));
		} else {
			return null;
		}
	}
	
}

 例子:

String familyName = Config.getObject("user.activity.hbase.familyName");

相关文章:

  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-08-03
  • 2022-01-03
  • 2022-02-05
  • 2021-11-16
猜你喜欢
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案