读取配置文件随记

来源:互联网 发布:学唱歌入门教程软件 编辑:程序博客网 时间:2024/06/08 13:38
import java.io.InputStream;import java.util.Properties;/** * 属性文件操作类 * */public class PropertyUtils {private final static String FILE_NAME = "config.properties"; private static Properties property = null; private PropertyUtils(){}static{if(null == property){property = new Properties();}try {//读取src目录下的配置文件InputStream is = PropertyUtils.class.getClassLoader().getResourceAsStream(FILE_NAME);//读取PropertyUtils.java所在文件夹下的配置文件//InputStream is =  PropertyUtils.class.getResourceAsStream(FILE_NAME);property.load(is);} catch (Exception e) {e.printStackTrace();}}public static String getProperty(String key){return property.getProperty(key);}}


	
				
		
原创粉丝点击