Skip to content

Commit 10811b3

Browse files
authored
Merge pull request #17 from mengpengfei/master
//问题说明 使用中发现原来客户端打jar包后,在另一个项目中引用,另一个项目打jar包后运行时找不到客户端配置文件
2 parents 7332ac5 + 560e831 commit 10811b3

File tree

1 file changed

+72
-42
lines changed

1 file changed

+72
-42
lines changed

src/org/csource/common/IniFileReader.java

Lines changed: 72 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -128,60 +128,90 @@ public String[] getValues(String name)
128128

129129
private void loadFromFile(String conf_filename) throws FileNotFoundException, IOException
130130
{
131-
FileReader fReader;
132-
BufferedReader buffReader;
133-
String line;
134-
String[] parts;
131+
//修改人 孟鹏飞,问题说明 使用中发现原来客户端打jar包后,在另一个项目中引用,另一个项目打jar包后运行时找不到客户端配置文件 ,能不能把我名字加上,以后好找工作
132+
// FileReader fReader;
133+
// BufferedReader buffReader;
134+
// String line;
135+
// String[] parts;
135136
String name;
136137
String value;
137138
Object obj;
138139
ArrayList valueList;
139-
140-
fReader = new FileReader(conf_filename);
141-
buffReader = new BufferedReader(fReader);
140+
InputStream is=null;
141+
// fReader = new FileReader(conf_filename);
142+
// buffReader = new BufferedReader(fReader);
142143
this.paramTable = new Hashtable();
143144

144145
try
145146
{
146-
while ((line=buffReader.readLine()) != null)
147-
{
148-
line = line.trim();
149-
if (line.length() == 0 || line.charAt(0) == '#')
150-
{
151-
continue;
152-
}
153-
154-
parts = line.split("=", 2);
155-
if (parts.length != 2)
156-
{
157-
continue;
158-
}
159-
160-
name = parts[0].trim();
161-
value = parts[1].trim();
147+
// while ((line=buffReader.readLine()) != null)
148+
// {
149+
// line = line.trim();
150+
// if (line.length() == 0 || line.charAt(0) == '#')
151+
// {
152+
// continue;
153+
// }
154+
//
155+
// parts = line.split("=", 2);
156+
// if (parts.length != 2)
157+
// {
158+
// continue;
159+
// }
160+
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(conf_filename);
161+
// System.out.println(conf_filename+"========================================");
162+
Properties props = new Properties();
163+
props.load(is);
164+
Iterator<Map.Entry<Object, Object>> it = props.entrySet().iterator();
165+
while (it.hasNext()) {
166+
Map.Entry<Object, Object> entry = it.next();
167+
name= entry.getKey().toString();
168+
value = entry.getValue().toString();
169+
// System.out.println(name+"======================================");
170+
obj = this.paramTable.get(name);
171+
if (obj == null)
172+
{
173+
this.paramTable.put(name, value);
174+
}
175+
else if (obj instanceof String)
176+
{
177+
valueList = new ArrayList();
178+
valueList.add(obj);
179+
valueList.add(value);
180+
this.paramTable.put(name, valueList);
181+
}
182+
else
183+
{
184+
valueList = (ArrayList)obj;
185+
valueList.add(value);
186+
}
187+
}
188+
// name = parts[0].trim();
189+
// value = parts[1].trim();
162190

163-
obj = this.paramTable.get(name);
164-
if (obj == null)
165-
{
166-
this.paramTable.put(name, value);
167-
}
168-
else if (obj instanceof String)
169-
{
170-
valueList = new ArrayList();
171-
valueList.add(obj);
172-
valueList.add(value);
173-
this.paramTable.put(name, valueList);
174-
}
175-
else
176-
{
177-
valueList = (ArrayList)obj;
178-
valueList.add(value);
179-
}
180-
}
191+
// obj = this.paramTable.get(name);
192+
// if (obj == null)
193+
// {
194+
// this.paramTable.put(name, value);
195+
// }
196+
// else if (obj instanceof String)
197+
// {
198+
// valueList = new ArrayList();
199+
// valueList.add(obj);
200+
// valueList.add(value);
201+
// this.paramTable.put(name, valueList);
202+
// }
203+
// else
204+
// {
205+
// valueList = (ArrayList)obj;
206+
// valueList.add(value);
207+
// }
208+
// }
181209
}
182210
finally
183211
{
184-
fReader.close();
212+
if (is!=null)
213+
is.close();
214+
// fReader.close();
185215
}
186216
}
187217
}

0 commit comments

Comments
 (0)