private void loadProperties()
{
//更新时间
this.lastModified = file.lastModified();
try
{
logger.info("The properties file[" + getPath() + "] loading ...");
FileInputStream in = new FileInputStream(file);
prop.load(in);
//print all properties
Enumeration<?> enu = prop.propertyNames();
StringBuffer buf = new StringBuffer();
while (enu.hasMoreElements())
{
String key = (String)enu.nextElement();
buf.append(" key: ").append(key).append(", value: ").append(prop.getProperty(key)).append("\n");
}
logger.info(buf.toString());
logger.info("The properties file[" + getPath() + "] load complete.");
//如果是log4J.properties文件更新,需要加载配置以便立即生效
if ("log4j.properties".equalsIgnoreCase(getFileName()))
{
PropertyConfigurator.configure(getProperties());
}
in.close();
}
catch (FileNotFoundException e)
{
logger.error("The file[" + getPath() + "] doesn't exist, reload file unsuccess.");
e.printStackTrace();
}
catch (IOException e)
{
logger.error("System IO Error, reload file[" + getPath() + "] unsuccess.");
e.printStackTrace();
}
}
//加载枚举文件
private void loadXml()
{
//更新时间
enumerateFiles.get(currentEnumFilePath).setEnumLastModifieds(enumerateFiles.get(currentEnumFilePath).getEnumFile().lastModified());
//KXml解析器
KXmlParser parser = new KXmlParser ();
//转换为Element
Document doc = new Document();
try
{
logger.info("The properties file[" + currentEnumFilePath + "] loading ...");
//打印原文件
println();
//解析文件
FileInputStream in = new FileInputStream(enumerateFiles.get(currentEnumFilePath).getEnumFile());
InputStreamReader reader = new InputStreamReader(in);
parser.setInput(reader);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
doc.parse(parser);
enumerateFiles.get(currentEnumFilePath).setEnumElement(doc.getRootElement());
//logger.info("The file load:" + xmlBuf.toString());
logger.info("The properties file[" + currentEnumFilePath + "] load complete.");
}
catch (XmlPullParserException e)
{
logger.error("The file[" + currentEnumFilePath + "] parser error,please check again.");
e.printStackTrace();
}
catch (FileNotFoundException e)
{
logger.error("The file[" + currentEnumFilePath + "] doesn't exist, reload file unsuccess.");
e.printStackTrace();
}
catch (IOException e)
{
logger.error("System IO Error, reload file[" + currentEnumFilePath + "] unsuccess.");
e.printStackTrace();
}
catch (Exception e)
{
logger.error("loadXml file[" + currentEnumFilePath + "] unsuccess.");
e.printStackTrace();
}
}
{
//更新时间
this.lastModified = file.lastModified();
try
{
logger.info("The properties file[" + getPath() + "] loading ...");
FileInputStream in = new FileInputStream(file);
prop.load(in);
//print all properties
Enumeration<?> enu = prop.propertyNames();
StringBuffer buf = new StringBuffer();
while (enu.hasMoreElements())
{
String key = (String)enu.nextElement();
buf.append(" key: ").append(key).append(", value: ").append(prop.getProperty(key)).append("\n");
}
logger.info(buf.toString());
logger.info("The properties file[" + getPath() + "] load complete.");
//如果是log4J.properties文件更新,需要加载配置以便立即生效
if ("log4j.properties".equalsIgnoreCase(getFileName()))
{
PropertyConfigurator.configure(getProperties());
}
in.close();
}
catch (FileNotFoundException e)
{
logger.error("The file[" + getPath() + "] doesn't exist, reload file unsuccess.");
e.printStackTrace();
}
catch (IOException e)
{
logger.error("System IO Error, reload file[" + getPath() + "] unsuccess.");
e.printStackTrace();
}
}
//加载枚举文件
private void loadXml()
{
//更新时间
enumerateFiles.get(currentEnumFilePath).setEnumLastModifieds(enumerateFiles.get(currentEnumFilePath).getEnumFile().lastModified());
//KXml解析器
KXmlParser parser = new KXmlParser ();
//转换为Element
Document doc = new Document();
try
{
logger.info("The properties file[" + currentEnumFilePath + "] loading ...");
//打印原文件
println();
//解析文件
FileInputStream in = new FileInputStream(enumerateFiles.get(currentEnumFilePath).getEnumFile());
InputStreamReader reader = new InputStreamReader(in);
parser.setInput(reader);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
doc.parse(parser);
enumerateFiles.get(currentEnumFilePath).setEnumElement(doc.getRootElement());
//logger.info("The file load:" + xmlBuf.toString());
logger.info("The properties file[" + currentEnumFilePath + "] load complete.");
}
catch (XmlPullParserException e)
{
logger.error("The file[" + currentEnumFilePath + "] parser error,please check again.");
e.printStackTrace();
}
catch (FileNotFoundException e)
{
logger.error("The file[" + currentEnumFilePath + "] doesn't exist, reload file unsuccess.");
e.printStackTrace();
}
catch (IOException e)
{
logger.error("System IO Error, reload file[" + currentEnumFilePath + "] unsuccess.");
e.printStackTrace();
}
catch (Exception e)
{
logger.error("loadXml file[" + currentEnumFilePath + "] unsuccess.");
e.printStackTrace();
}
}