.№愛の冰封
開始懂得逢場作戲,雖然有許多只是霧水情緣; 不過沒關系了,哪來那么多一生一世
BlogJava
首頁
新隨筆
聯系
聚合
管理
posts - 14, comments - 37, trackbacks - 0
JAVA讀取Properties(配置文件)工具類
以下這個類是在JAVA中如何讀取Properties配置文件:
1
package
cn.com.cinda.rtx.common;
2
3
import
java.io.BufferedReader;
4
import
java.io.FileReader;
5
import
java.io.IOException;
6
import
java.util.HashMap;
7
import
java.util.Properties;
8
import
java.util.
*
;
9
import
java.io.
*
;
10
11
12
public
class
IniReader
{
13
protected
LinkedHashMap sections;
//
使用
14
15
public
IniReader()
{
16
super
();
17
sections
=
new
LinkedHashMap();
18
}
19
20
public
LinkedHashMap getSections()
{
21
return
sections;
22
}
23
24
public
LinkedHashMap getSection(String sectionName)
{
25
if
(sections
!=
null
)
{
26
return
(LinkedHashMap) sections.get(sectionName);
27
}
else
{
28
return
null
;
29
}
30
}
31
32
public
String get(String sectionName, String key)
{
33
Map section1
=
(Map) sections.get(sectionName);
34
if
(section1
==
null
)
{
35
return
""
;
36
}
37
return
(String) section1.get(key);
38
}
39
40
41
public
void
load(String fileName)
throws
FileNotFoundException
{
42
InputStream is
=
null
;
43
try
{
44
is
=
new
FileInputStream(fileName);
45
load(is);
46
}
catch
(IOException e)
{
47
e.printStackTrace();
48
}
finally
{
49
if
(is
!=
null
)
{
50
try
{
51
is.close();
52
}
catch
(IOException e1)
{}
53
}
54
}
55
}
56
57
public
void
load(InputStream is)
throws
IOException
{
58
BufferedReader reader
=
new
BufferedReader(
new
InputStreamReader(is));
59
String line
=
null
;
60
String lastSectionName
=
null
;
61
while
((line
=
reader.readLine())
!=
null
)
{
62
line
=
line.trim();
63
if
(line.startsWith(
"
#
"
))
{
64
continue
;
65
}
66
if
(line.startsWith(
"
[
"
)
&&
line.endsWith(
"
]
"
))
{
67
lastSectionName
=
line.trim().substring(
1
, line.length()
-
1
);
68
sections.put(lastSectionName,
new
LinkedHashMap());
//
創建一個section
69
}
else
if
(line.length()
==
0
)
{
70
continue
;
71
}
else
{
72
if
(lastSectionName
!=
null
)
{
73
Map section
=
(Map) sections.get(lastSectionName);
74
int
index
=
line.indexOf(
'
=
'
);
75
String key
=
index
>
0
?
line.substring(
0
, index) : line;
//
如果沒有等號,直接做key和value
76
String value
=
index
>
0
?
line.substring(index
+
1
) : line;
77
section.put(key, value);
78
}
79
}
80
}
81
}
82
83
public
static
void
main(String[] args)
{
84
IniReader iniReader
=
new
IniReader();
85
try
{
86
FileInputStream fileInputStream
=
new
FileInputStream(
"
/etc/portalconf/jmsconfig.property
"
);
87
iniReader.load(fileInputStream);
88
Map sections
=
iniReader.getSection(
"
serverconf
"
);
89
java.util.Iterator it
=
sections.keySet().iterator();
90
while
(it.hasNext())
{
91
String key
=
(String) it.next();
92
System.out.println(key
+
"
=
"
+
sections.get(key));
93
}
94
95
}
catch
(IOException e)
{
96
e.printStackTrace();
97
}
98
}
99
}
100
101
102
posted on 2007-06-26 14:34
冰封的愛
閱讀(1695)
評論(0)
編輯
收藏
所屬分類:
技術
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
使用Axis開發Web Service程序
java中的日期格式化
在linux和unix中指定JVM內存大小
JAVA讀取Properties(配置文件)工具類
JAVA加密解密工具類
擴展ClassLoader定制類裝載器
java日期比較
java中生成32位隨機ID
Linux下常用壓縮格式的壓縮與解壓方法
Copyright ©2025 冰封的愛 Powered By:
博客園
模板提供:
滬江博客
<
2025年7月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2007年9月 (1)
2007年8月 (6)
2007年7月 (3)
2007年6月 (3)
文章分類
J2EE(64)
Linux(8)
常用工具(9)
開源項目(3)
技術(9)
文章檔案
2009年1月 (1)
2008年4月 (1)
2008年1月 (1)
2007年10月 (2)
2007年9月 (2)
2007年8月 (1)
2007年7月 (73)
2007年6月 (12)
相冊
冰封的相冊
搜索
最新評論
1.?re: 自動生成32位永不重復ID
444
--22
2.?re: 根據拼音首字母查詢人名(C#版)[未登錄]
好用,謝謝
--123
3.?re: java中生成32位隨機ID [未登錄]
手術
--想
4.?re: Jocky混淆JAVA代碼(保護你的JAVA項目)
求支持 JDK 1.7的版本
--pro
5.?re: Jocky混淆JAVA代碼(保護你的JAVA項目)
8530
--ss
閱讀排行榜
1.?學會放下(668)
2.?項目人生(407)
3.?IT外包值得體驗(405)
4.?小型軟件公司如何做大(399)
5.?2007年7月每日一句匯總(1)(369)
評論排行榜
1.?學會放下(0)
2.?2007年7月份 每日一句匯總(2)(0)
3.?2007年7月每日一句匯總(1)(0)
4.?英語每日一句(0)
5.?IT外包值得體驗(0)
主站蜘蛛池模板:
亚洲熟妇少妇任你躁在线观看无码
|
亚洲电影免费观看
|
91免费资源网站入口
|
美国毛片亚洲社区在线观看
|
亚洲午夜久久久久久久久电影网
|
亚洲精品无码国产片
|
狠狠色婷婷狠狠狠亚洲综合
|
1000部拍拍拍18勿入免费视频下载
|
亚洲一区二区三区深夜天堂
|
亚洲AV网站在线观看
|
性xxxxx大片免费视频
|
亚洲国产精品综合久久20
|
亚洲精品无码99在线观看
|
五月婷婷在线免费观看
|
美女被艹免费视频
|
亚洲性无码av在线
|
国产亚洲精品激情都市
|
成年轻人网站色免费看
|
成在线人视频免费视频
|
狠狠色香婷婷久久亚洲精品
|
亚洲一区二区女搞男
|
美女被免费视频网站a国产
|
亚洲AV蜜桃永久无码精品
|
最近2018中文字幕免费视频
|
色多多www视频在线观看免费
|
亚洲欧洲国产综合
|
亚洲精品无码99在线观看
|
一二三四在线播放免费观看中文版视频
|
亚洲?v女人的天堂在线观看
|
久久精品国产免费观看
|
丁香花在线观看免费观看图片
|
国产亚洲精aa在线看
|
亚洲另类激情综合偷自拍
|
亚洲国产人成精品
|
成年女人毛片免费视频
|
免费视频成人手机在线观看网址
|
国产亚洲精品AAAA片APP
|
亚洲成a人片在线观看精品
|
亚洲无删减国产精品一区
|
亚洲中文字幕无码永久在线
|
亚洲电影日韩精品
|