modified src/org/csource/common/IniFileReader.java

dev
mengpengfei 2017-04-14 15:55:23 +08:00
parent 7332ac55a9
commit c4c9d94656
1 changed files with 67 additions and 38 deletions

View File

@ -136,30 +136,36 @@ public class IniFileReader
String value; String value;
Object obj; Object obj;
ArrayList valueList; ArrayList valueList;
InputStream is=null;
fReader = new FileReader(conf_filename); // fReader = new FileReader(conf_filename);
buffReader = new BufferedReader(fReader); // buffReader = new BufferedReader(fReader);
this.paramTable = new Hashtable(); this.paramTable = new Hashtable();
try try
{ {
while ((line=buffReader.readLine()) != null) // while ((line=buffReader.readLine()) != null)
{ // {
line = line.trim(); // line = line.trim();
if (line.length() == 0 || line.charAt(0) == '#') // if (line.length() == 0 || line.charAt(0) == '#')
{ // {
continue; // continue;
} // }
//
parts = line.split("=", 2); // parts = line.split("=", 2);
if (parts.length != 2) // if (parts.length != 2)
{ // {
continue; // continue;
} // }
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(conf_filename);
name = parts[0].trim(); // System.out.println(conf_filename+"========================================");
value = parts[1].trim(); Properties props = new Properties();
props.load(is);
Iterator<Map.Entry<Object, Object>> it = props.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Object, Object> entry = it.next();
name= entry.getKey().toString();
value = entry.getValue().toString();
// System.out.println(name+"======================================");
obj = this.paramTable.get(name); obj = this.paramTable.get(name);
if (obj == null) if (obj == null)
{ {
@ -178,10 +184,33 @@ public class IniFileReader
valueList.add(value); valueList.add(value);
} }
} }
// name = parts[0].trim();
// value = parts[1].trim();
// obj = this.paramTable.get(name);
// if (obj == null)
// {
// this.paramTable.put(name, value);
// }
// else if (obj instanceof String)
// {
// valueList = new ArrayList();
// valueList.add(obj);
// valueList.add(value);
// this.paramTable.put(name, valueList);
// }
// else
// {
// valueList = (ArrayList)obj;
// valueList.add(value);
// }
// }
} }
finally finally
{ {
fReader.close(); if (is!=null)
is.close();
// fReader.close();
} }
} }
} }