.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 propertiesEnumeration<?> 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 (); //转换为ElementDocument 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();}}