码迷,mamicode.com
首页 > 编程语言 > 详细

Java获取.properties文件

时间:2014-07-05 23:47:03      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:java

	@SuppressWarnings("rawtypes")
	public static void getProperties() {
		
		Properties properties = null;
		InputStream in = null;
		try {
			properties = new Properties();
	
			//获取文件
			in = Object.class.getResourceAsStream("/config.properties");
			properties.load(in);
			
			Enumeration enumerations= properties.propertyNames();
			
			//遍历输出
			while(enumerations.hasMoreElements()){
				String key=(String)enumerations.nextElement();
				String value=properties.getProperty(key);
				
				System.out.println(key+"="+value);		
			}
			
		} catch (IOException e) {
			e.printStackTrace();

		//关闭InputStream
		} finally{
			if(in != null){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

Java获取.properties文件,布布扣,bubuko.com

Java获取.properties文件

标签:java

原文地址:http://blog.csdn.net/wintersweetsugar/article/details/36871459

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!