How to process the Properties file!
2009-02-25 14:40
218 查看
Quote From:http://blog.csdn.net/daryl715/archive/2007/09/26/1802204.aspx
Properties pro = new Properties();
try {
InputStream inStr = ClassLoader.getSystemResourceAsStream("wahaha.properties");
pro.load(inStr);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//propertyNames(),返回属性列表中所有键的枚举
Enumeration enu2=pro.propertyNames();
while(enu2.hasMoreElements()){
String key = (String)enu2.nextElement();
System.out.println(key);
}
//Properties 继承于 Hashtable,elements()是Hashtable的方法,返回哈希表中的值的枚举。
Enumeration enu=pro.elements();
while(enu.hasMoreElements()){
String key = (String)enu.nextElement();
System.out.println(key);
}
//Properties 继承于 Hashtable,entrySet()是Hashtable的方法,
//返回此 Hashtable 中所包含的键的 Set 视图。此 collection 中每个元素都是一个 Map.Entry
Iterator it=pro.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry=(Map.Entry)it.next();
Object key = entry.getKey();
Object value = entry.getValue();
System.out.println(key +":"+value);
}
假设wahaha.properties中内容为:
------------------------------
name1=xxxx
name2=yyyyy
name3=zzzzzzz
------------------------------
上面的代码将会输出:
--------------------------
name1
name2
name3
xxxx
yyyyy
zzzzzzz
name1:xxxx
name2:yyyyy
name3:zzzzzzz
---------------------------------
Properties pro = new Properties();
try {
InputStream inStr = ClassLoader.getSystemResourceAsStream("wahaha.properties");
pro.load(inStr);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//propertyNames(),返回属性列表中所有键的枚举
Enumeration enu2=pro.propertyNames();
while(enu2.hasMoreElements()){
String key = (String)enu2.nextElement();
System.out.println(key);
}
//Properties 继承于 Hashtable,elements()是Hashtable的方法,返回哈希表中的值的枚举。
Enumeration enu=pro.elements();
while(enu.hasMoreElements()){
String key = (String)enu.nextElement();
System.out.println(key);
}
//Properties 继承于 Hashtable,entrySet()是Hashtable的方法,
//返回此 Hashtable 中所包含的键的 Set 视图。此 collection 中每个元素都是一个 Map.Entry
Iterator it=pro.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry=(Map.Entry)it.next();
Object key = entry.getKey();
Object value = entry.getValue();
System.out.println(key +":"+value);
}
假设wahaha.properties中内容为:
------------------------------
name1=xxxx
name2=yyyyy
name3=zzzzzzz
------------------------------
上面的代码将会输出:
--------------------------
name1
name2
name3
xxxx
yyyyy
zzzzzzz
name1:xxxx
name2:yyyyy
name3:zzzzzzz
---------------------------------
相关文章推荐
- How do I get multiple process to log to the same file?
- How To Trace The Remote File Server (RFS) Process In Physical Standby Database (Doc ID 1481125.1)
- 【Ant】How to print all the system properties in Ant build file
- How to access a value defined in the application.properties file in Spring Boot ( Externalized Conf)
- How to get the file's icon using C++ - 用C++如何获取文件的图标
- How to remove the copyright box on a paper that uses the ACM sig-alternate.cls class file?
- How to know is the file exist in C++ - 在C++中如何判断文件是否存在
- How to delete the log file of log4j dynamically
- How to Create Modifiers Using the API QP_MODIFIERS_PUB.PROCESS_MODIFIERS
- How To Get Application Path,And How To Get The Path's Directory,File Name,And Type Info(如何得到运行程序的路径,以及如何得到路径的文件夹,文件名,以及类型等等信息)
- Project has no default.properties file! Edit the project properties to set one.错误解决方案
- how to find the log file of mysql
- How to Access and Use the Windows Hosts File in Windows 7 and Vista
- import Android项目出现Project has no project.properties file! Edit the project properties to set one.
- How to get a high quality system in the developing process?
- nrf51822 secure DFU by OTA: How to Set Password in the DFU zip File
- THE JAM BUILDING TOOL-Jamfile how to
- Project has no default.properties file! Edit the project properties to set one.错误解决方案
- HOWTO Use the GCC specs file
- 引入工程出现这个 Project has no project.properties file! Edit the project properties to set one.问题的总结方案