1 | package com.luang.util.properties; |
03 | import java.io.FileInputStream; |
04 | import java.io.FileOutputStream; |
05 | import java.io.IOException; |
06 | import java.io.InputStream; |
07 | import java.io.OutputStream; |
09 | import java.util.Enumeration; |
10 | import java.util.HashMap; |
12 | import java.util.Properties; |
13 | import java.util.ResourceBundle; |
20 | * @descproperties资源文件解析工具 |
22 | * @datatimeApr7,20133:58:45PM |
25 | public class PropertiesUtil { |
27 | private Properties props; |
30 | public PropertiesUtil(String fileName){ |
31 | readProperties(fileName); |
33 | private void readProperties(String fileName){ |
36 | InputStream fis=getClass().getResourceAsStream(fileName); |
38 | uri = this .getClass().getResource( "/dbConfig.properties" ).toURI(); |
46 | public String getProperty(Stringkey){ |
47 | return props.getProperty(key); |
53 | public Map getAllProperty(){ |
55 | Enumeration enu=props.propertyNames(); |
56 | while (enu.hasMoreElements()) { |
57 | String key=(String)enu.nextElement(); |
58 | String value=props.getProperty(key); |
66 | public void printProperties(){ |
67 | props.list(System.out); |
72 | public void writeProperties(String key,Stringvalue){ |
74 | OutputStream fos= new FileOutputStream( new File(uri)); |
75 | props.setProperty(key, value); |
76 | // 将此Properties表中的属性列表(键和元素对)写入输出流 |
77 | props.store(fos, "『comments』Update
key:" + key); |
82 | public static void main(String[] args){ |
83 | PropertiesUtil
util= new PropertiesUtil( "src/dbConfig.properties" ); |
84 | util.writeProperties( "dbtype" , "MSSQL" ); |
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理