阅读背景:

java实现读取配置文件生成map对象

来源:互联网 
package com.tygy.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

public class ReadProperties {

	/**
	* 文件路径
	*/
	private static String filePath = "resources/clounm.properties";

	/**
	* 获取properties文件中的内容,并返回map
	* 
	* @return
	*/
	public static Map<String, String> getProperties() {
		Map<String, String> map = new HashMap<String, String>();
		InputStream in = null;
		Properties p = new Properties();;
		try {
			in = new BufferedInputStream(new FileInputStream(new File(filePath)));
			p.load(in);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Set<Entry<Object, Object>> entrySet = p.entrySet();
		for (Entry<Object, Object> entry : entrySet) {
			map.put((String) entry.getKey(), (String) entry.getValue());
		}
		return map;
	}

}
package com.tygy.util;

import java.io.Buff



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: