Java获取.properties文件

时间:2014-07-05 23:47:03   收藏:0   阅读:290
	@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

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!