读取国航三字码的PROPERTIES
三字码的PROPERTIES文件
package com.airchina.test;import java.io.IOException;import java.io.InputStream;import java.util.Enumeration;import java.util.Properties;public class TestEnum { public static void main(String[] args) { Properties prop = new Properties();InputStream inputStream=null;try {inputStream= new TestEnum().getClass().getResourceAsStream("/city.properties");prop.load(inputStream);Enumeration<?> en = prop.propertyNames();//返回属性列表中所有键的枚举String obj = "";//obj置空String cityName= "";while (en.hasMoreElements()) {//测试此枚举是否包含更多的元素。obj = (String) en.nextElement();//obj即为city.properties中获得的三字码cityName=prop.getProperty(obj);//cityName即为city.properties中获得的城市名称System.out.println(obj+"------"+cityName+"\n");}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {try {if (null != inputStream)//如果inputStream非空{inputStream.close();//关闭inputStreaminputStream = null;//inputStream置空s}} catch (IOException e) {//抓住IO错误e.printStackTrace();//打印}} }}