首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

读取国航3字码的PROPERTIES

2013-11-08 
读取国航三字码的PROPERTIES三字码的PROPERTIES文件package com.airchina.testimport java.io.IOExceptio

读取国航三字码的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();//打印}}    }}



热点排行