欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JAVA项目读取配置文件【相对路径】

程序员文章站 2022-05-10 09:18:25
...
package com.*.*.web.utils;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.core.io.support.PropertiesLoaderUtils;



public class CacheAgreementInfo {  
	
	@SuppressWarnings("unused")
	public static Map<String, String> CacheAgreementInfo() throws Exception {
		
		Map<String, String> agreementMap = new HashMap<String, String>();
		Properties props = new Properties();
			try {
				props=PropertiesLoaderUtils.loadAllProperties("*.properties");
				for(Object key:props.keySet()){
					String valueIs = (String)props.get(key);
					String value=new String(valueIs.getBytes("ISO8859-1"),"UTF-8");
					agreementMap.put((String) key, value);
				}
			} catch (IOException e) {
				throw new Exception("读取协议文件失败");
			}
		
		return agreementMap;
	}

	
	public static void main(String[] args) throws Exception {
		CacheAgreementInfo();
	}
}  

*交流分享,杜绝私藏。崇尚开源