读取比较简单~~
保存的时候,如果使用默认的property.store()方法,会把所有的注释都忽略~
所以自己采用读取文件的方式,来实现保存property~
/** * Update the key's value to new value ,and write back to the Configuration * file * * @param configFilePath * Configuration file * @param key * the key * @param value * the new value */ public static Boolean updateProperty(String configFilePath, String key, String value) { // Read File BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(configFilePath)); } catch (FileNotFoundException e) { Log.getInstance().fine("Can not find file: " + configFilePath + "."); //$NON-NLS-1$ //$NON-NLS-2$ } StringBuilder builder = new StringBuilder(); String tempLine; String tempValue; // Find the property and update try { while ((tempLine = reader.readLine()) != null) { if (tempLine.trim().startsWith(COMMENT_FALG)) { builder.append(tempLine).append(LINE_SEPARATOR); continue; } if (tempLine.contains(key)) { tempValue = tempLine.trim().substring(key.length()); if (tempValue.trim().startsWith(EQUAL_FLAG)) { tempLine = key + EQUAL_FLAG + value; } } builder.append(tempLine).append(LINE_SEPARATOR); } reader.close(); } catch (IOException e) { Log.getInstance().fine("Read configuration file: " + configFilePath + " error."); //$NON-NLS-1$ //$NON-NLS-2$ e.printStackTrace(); } // Update File BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(configFilePath)); writer.append(builder.toString()); writer.close(); } catch (IOException e) { Log.getInstance().fine("Update configuration file: " + configFilePath + " error."); //$NON-NLS-1$ //$NON-NLS-2$ } return true; } /** * Get value from configuration file by key * * @param configFilePath * configuration file path * * @param key * the key * * @return the value */ public static String getProperty(String configFilePath, String key) { Properties prop = new Properties(); try { prop.load(new FileInputStream(configFilePath)); } catch (FileNotFoundException e) { Log.getInstance().fine("Can not find file: " + configFilePath + "."); //$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) { Log.getInstance().fine("Error read configuration file: " + configFilePath + " ."); //$NON-NLS-1$ //$NON-NLS-2$ } return prop.getProperty(key); }
您还没有登录,请您登录后再发表评论
NULL 博文链接:https://liuwyong11.iteye.com/blog/611174
activiti6.0用户手册,pdf英文版,后期将会为大家上传中文版,敬请期待!
configure.properties
maven私有服务器搭建工具nexus的war包,可直接放在如tomcat之类的服务器下部署运行。
源码内带数据库, 能实现基本的功能,只要将其部署到Myeclipse或eclipse中,添加到数据库,修改一下配置文件jbdc.propertes中的数据库链接就可以正常运行了
样品监测应用 一个包含Swagger servlet,Hystrix servlet的配置以及可选的Camel Endpoint servlet的库,它在码头服务器中运行。... 要更改配置,请将swagger_api.propertes文件添加到类路径的根目录。
连接各种数据库的配置都写在properties文件里,方便查询使用
相关推荐
NULL 博文链接:https://liuwyong11.iteye.com/blog/611174
activiti6.0用户手册,pdf英文版,后期将会为大家上传中文版,敬请期待!
configure.properties
maven私有服务器搭建工具nexus的war包,可直接放在如tomcat之类的服务器下部署运行。
源码内带数据库, 能实现基本的功能,只要将其部署到Myeclipse或eclipse中,添加到数据库,修改一下配置文件jbdc.propertes中的数据库链接就可以正常运行了
样品监测应用 一个包含Swagger servlet,Hystrix servlet的配置以及可选的Camel Endpoint servlet的库,它在码头服务器中运行。... 要更改配置,请将swagger_api.propertes文件添加到类路径的根目录。
连接各种数据库的配置都写在properties文件里,方便查询使用