`
gcgmh
  • 浏览: 348925 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

资源文件加载的的类

阅读更多
public class ReadProperties {
	/*
	 * 加载指定路径下的配置文件信息,并获得Properties对象
	 *  (non-Javadoc)
	 * @see com.voole.interf.IProperties#getProperties()
	 * @return Properties对象
	 */
	public static Properties getProperties() {
		return getProperties("/config.properties");
	}
	
	public static Properties getProperties(String path) {
		InputStream inStream = ReadProperties.class.getResourceAsStream(path);
		Properties prop = new Properties();
		try {
			if(inStream != null){
				prop.load(inStream);
				inStream.close();
			}
		} catch (IOException e) {
			System.out.println("加载指定路径下的配置文件出错!"+e.getMessage());
		}
		return prop;
	}
	
	//使用
	public static void main(String[] args) {
		Properties pr = ReadProperties.getProperties();
		System.out.println("mysql connection -- " + pr.getProperty("SQL_DRIVER"));
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics