Java获取.properties文件

	@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文件

上一篇:Javascript学习--------认识window窗口对象


下一篇:Python 查找Twitter中最流行(转载最多)的10个Tweet