阅读背景:

读取配置文件的工具类(properties文件和xml文件)

来源:互联网 

读取properties文件的工具类



import java.io.File;
import java.io.IOException;
import java.util.Properties;

/**
 * 读取properties文件的工具类
 * @author 
 *
 */
public class PropertyUtil {
	private static PropertyUtil propUtil;
	private static Properties props;
	private PropertyUtil(String path) throws IOException{
		init(path);
	}
	private void init(String path) throws IOException{
		props = new Properties();
		props.load(PropertyUtil.class.getClassLoader().getResourceAsStream(path));
	}
	
	public static PropertyUtil getInstance(String path) throws IOException{
		if(propUtil == null){
			propUtil = new PropertyUtil(path);
		}
		return propUtil;
	}
	
	public static String getProperties(String key){
		return props.getProperty(key);
	}
}


import java.io.File;
im



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

分享到: