锘??xml version="1.0" encoding="utf-8" standalone="yes"?>在线中文字幕第一区,国产区精品区,欧美日韩一二三区http://www.aygfsteel.com/Freax/zh-cnWed, 18 Jun 2025 06:39:40 GMTWed, 18 Jun 2025 06:39:40 GMT60鐢↗AVA璇誨彇INI鏂囦歡http://www.aygfsteel.com/Freax/archive/2006/07/06/56911.htmlFreaxFreaxThu, 06 Jul 2006 02:49:00 GMThttp://www.aygfsteel.com/Freax/archive/2006/07/06/56911.htmlhttp://www.aygfsteel.com/Freax/comments/56911.htmlhttp://www.aygfsteel.com/Freax/archive/2006/07/06/56911.html#Feedback0http://www.aygfsteel.com/Freax/comments/commentRss/56911.htmlhttp://www.aygfsteel.com/Freax/services/trackbacks/56911.html

聽聽1 /*
聽聽2
聽聽3 *聽@(#)聽IniReader.java聽
聽聽4
聽聽5 *聽Created聽on聽2004-10-14聽
聽聽6
聽聽7 *聽Created聽by聽James聽Fancy聽
聽聽8
聽聽9 */

聽10
聽11 import 聽java.io.BufferedReader;聽
聽12
聽13 import 聽java.io.FileReader;聽
聽14
聽15 import 聽java.io.IOException;聽
聽16
聽17 import 聽java.util.HashMap;聽
聽18
聽19 import 聽java.util.Properties;聽
聽20
聽21 /**
聽22
聽23 *聽 @author 聽James聽Fancy聽
聽24
聽25 */

聽26
聽27 public class 聽IniReader聽 {聽
聽28
聽29 protected 聽HashMap聽sections聽 = new 聽HashMap();聽
聽30
聽31 private transient 聽String聽currentSecion;聽
聽32
聽33 private transient 聽Properties聽current;聽
聽34
聽35 public 聽IniReader(String聽filename)聽 throws 聽IOException聽 {聽
聽36
聽37 BufferedReader聽reader聽 = new 聽BufferedReader( new 聽FileReader(filename));聽
聽38
聽39 read(reader);聽
聽40
聽41 reader.close();聽
聽42
聽43 }

聽44
聽45 protected void 聽read(BufferedReader聽reader)聽 throws 聽IOException聽 {聽
聽46
聽47 String聽line;聽
聽48
聽49 while 聽((line聽 = 聽reader.readLine())聽 != null )聽 {聽
聽50
聽51 parseLine(line);聽
聽52
聽53 }

聽54
聽55 }

聽56
聽57 protected void 聽parseLine(String聽line)聽 {聽
聽58
聽59 line聽 = 聽line.trim();聽
聽60
聽61 if 聽(line.matches( " \\[.*\\] " ))聽 {聽
聽62
聽63 // 聽濡傛灉鏄燡DK聽1.4(涓嶅惈1.4)浠ヤ笅鐗堟湰錛屼慨鏀逛負聽
聽64
聽65 // 聽if聽(line.startsWith("[")聽&&聽line.endsWith("]"))聽{聽
聽66
聽67 if 聽(current聽 != null )聽 {聽
聽68
聽69 sections.put(currentSecion,聽current);聽
聽70
聽71 }

聽72
聽73 currentSecion聽 = 聽line.replaceFirst( " \\[(.*)\\] " ,聽 " $1 " );聽
聽74
聽75 // 聽JDK聽浣庝簬聽1.4聽鏃堵?br /> 聽76
聽77 // 聽currentSection聽=聽line.substring(1,聽line.length()聽-聽1);聽
聽78
聽79 current聽 = new 聽Properties();聽
聽80
聽81 }
else if 聽(line.matches( " .*=.* " ))聽 {聽
聽82
聽83 // 聽JDK聽浣庝簬聽1.4聽鏃堵?br /> 聽84
聽85 // 聽}聽else聽if聽(line.indexOf('=')聽>=聽0)聽{聽
聽86
聽87 int 聽i聽 = 聽line.indexOf( ' = ' );聽
聽88
聽89 String聽name聽 = 聽line.substring( 0 ,聽i);聽
聽90
聽91 String聽value聽 = 聽line.substring(i聽 + 1 );聽
聽92
聽93 current.setProperty(name,聽value);聽
聽94
聽95 }

聽96
聽97 }

聽98
聽99 public 聽String聽getValue(String聽section,聽String聽name)聽 {聽
100
101 Properties聽p聽 = 聽(Properties)聽sections.get(section);聽
102
103 if 聽(p聽 == null )聽 {聽
104
105 return null ;聽
106
107 }

108
109 String聽value聽 = 聽p.getProperty(name);聽
110
111 return 聽value;聽
112
113 }

114
115 }

116
117 紺轟緥錛毬?br /> 118
119 public static void 聽main(String[]聽args)聽 throws 聽IOException聽 {聽
120
121 IniReader聽reader聽 = new 聽IniReader( " E:\\james\\win.ini " );聽
122
123 System.out.println(reader.getValue( " MCI聽Extensions.BAK " ,聽 " asf " ));聽
124
125 }

126
127


Freax 2006-07-06 10:49 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 和静县| 大足县| 台安县| 定襄县| 怀远县| 镇远县| 开封市| 阿巴嘎旗| 长丰县| 金塔县| 兴仁县| 溧阳市| 浏阳市| 新宾| 皮山县| 宜章县| 舞钢市| 云和县| 从化市| 富蕴县| 泉州市| 上饶县| 南平市| 五家渠市| 盱眙县| 商洛市| 祥云县| 昆山市| 泸水县| 宁城县| 盐边县| 方正县| 安仁县| 舞阳县| 新宁县| 镇远县| 油尖旺区| 晋城| 嘉荫县| 新余市| 洛阳市|