在java中读取配置文件信息

public class PropertyUtil {
	public static final Properties PROP = new Properties();

	/**
	 * 读取配置文件的内容(key,value)
	 * 
	 * @param key
	 * @return key对应的value
	 */
	public static String get(String key) {
		if (PROP.isEmpty()) {
			try {
				InputStream in = PropertyUtil.class.getResourceAsStream("/config.properties");
				PROP.load(in);
				in.close();
			} catch (Exception e) {}
		}
		return PROP.getProperty(key);
	}
}
  • 在resources文件下新建config.properties文件
websitepath=E:\\code\\landtax\\landtax\\
standardcondition=\"C_CD\"<=0.2
filePathTDQS=D:\\webspace\\import\\\u571F\u5730\u6743\u5C5E\u4FE1\u606F.xlsx

  • 调用方法
String filePathTDQS = PropertyUtil.get("filePathTDQS");
posted @ 2017-07-04 16:02  KronChan  阅读(628)  评论(0编辑  收藏  举报