.xml正向反向取值(之五)

FileListener类,续:

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());
}
}
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();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值