Java配置文件Properties的讀取、寫入與更新操做

<div class="htmledit_views">html

<ol start="1" class="dp-j" style="border:none;color:rgb(92,92,92);font-family:Consolas, 'Courier New', Courier, mono, serif;line-height:26px;"><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">/**&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">*&nbsp;實現對Java配置文件Properties的讀取、寫入與更新操做&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">*/</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">package</span><span style="border:none;background-color:inherit;">&nbsp;test;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.io.BufferedInputStream;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.io.FileInputStream;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.io.FileNotFoundException;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.io.FileOutputStream;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.io.IOException;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.io.InputStream;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.io.OutputStream;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">import</span><span style="border:none;background-color:inherit;">&nbsp;java.util.Properties;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">/**&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">*&nbsp;@author&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">*&nbsp;@version&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">*/</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">public</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">class</span><span style="border:none;background-color:inherit;">&nbsp;SetSystemProperty&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//屬性文件的路徑&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">static</span><span style="border:none;background-color:inherit;">&nbsp;String&nbsp;profilepath=</span><span class="string" style="border:none;color:#FF0000;background-color:inherit;">"mail.properties"</span><span style="border:none;background-color:inherit;">;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">/**&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;採用靜態方法&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">private</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">static</span><span style="border:none;background-color:inherit;">&nbsp;Properties&nbsp;props&nbsp;=&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;Properties();&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">static</span><span style="border:none;background-color:inherit;">&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">try</span><span style="border:none;background-color:inherit;">&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;props.load(<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;FileInputStream(profilepath));&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">catch</span><span style="border:none;background-color:inherit;">&nbsp;(FileNotFoundException&nbsp;e)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.exit(-<span class="number" style="border:none;color:rgb(192,0,0);background-color:inherit;">1</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">catch</span><span style="border:none;background-color:inherit;">&nbsp;(IOException&nbsp;e)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.exit(-<span class="number" style="border:none;color:rgb(192,0,0);background-color:inherit;">1</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">/**&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;讀取屬性文件中相應鍵的值&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;key&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;主鍵&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;String&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">public</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">static</span><span style="border:none;background-color:inherit;">&nbsp;String&nbsp;getKeyValue(String&nbsp;key)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">return</span><span style="border:none;background-color:inherit;">&nbsp;props.getProperty(key);&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">/**&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;根據主鍵key讀取主鍵的值value&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;filePath&nbsp;屬性文件路徑&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;key&nbsp;鍵名&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">public</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">static</span><span style="border:none;background-color:inherit;">&nbsp;String&nbsp;readValue(String&nbsp;filePath,&nbsp;String&nbsp;key)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Properties&nbsp;props&nbsp;=&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;Properties();&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">try</span><span style="border:none;background-color:inherit;">&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;in&nbsp;=&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;BufferedInputStream(</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;FileInputStream(&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filePath));&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;props.load(in);&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;value&nbsp;=&nbsp;props.getProperty(key);&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(key&nbsp;+<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"鍵的值是:"</span><span style="border:none;background-color:inherit;">+&nbsp;value);&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">return</span><span style="border:none;background-color:inherit;">&nbsp;value;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">catch</span><span style="border:none;background-color:inherit;">&nbsp;(Exception&nbsp;e)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">return</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">null</span><span style="border:none;background-color:inherit;">;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">/**&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;更新(或插入)一對properties信息(主鍵及其鍵值)&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;若是該主鍵已經存在,更新該主鍵的值;&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;若是該主鍵不存在,則插件一對鍵值。&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;keyname&nbsp;鍵名&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;keyvalue&nbsp;鍵值&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">public</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">static</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">void</span><span style="border:none;background-color:inherit;">&nbsp;writeProperties(String&nbsp;keyname,String&nbsp;keyvalue)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">try</span><span style="border:none;background-color:inherit;">&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;調用&nbsp;Hashtable&nbsp;的方法&nbsp;put,使用&nbsp;getProperty&nbsp;方法提供並行性。&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;強制要求爲屬性的鍵和值使用字符串。返回值是&nbsp;Hashtable&nbsp;調用&nbsp;put&nbsp;的結果。&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStream&nbsp;fos&nbsp;=&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;FileOutputStream(profilepath);&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;props.setProperty(keyname,&nbsp;keyvalue);&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;以適合使用&nbsp;load&nbsp;方法加載到&nbsp;Properties&nbsp;表中的格式,&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;將此&nbsp;Properties&nbsp;表中的屬性列表(鍵和元素對)寫入輸出流&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;props.store(fos,&nbsp;<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"Update&nbsp;'"</span><span style="border:none;background-color:inherit;">&nbsp;+&nbsp;keyname&nbsp;+&nbsp;</span><span class="string" style="border:none;color:#FF0000;background-color:inherit;">"'&nbsp;value"</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">catch</span><span style="border:none;background-color:inherit;">&nbsp;(IOException&nbsp;e)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.err.println(<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"屬性文件更新錯誤"</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">/**&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;更新properties文件的鍵值對&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;若是該主鍵已經存在,更新該主鍵的值;&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;若是該主鍵不存在,則插件一對鍵值。&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;keyname&nbsp;鍵名&nbsp;</span>&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;keyvalue&nbsp;鍵值&nbsp;</span>&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;"><span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">public</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">void</span><span style="border:none;background-color:inherit;">&nbsp;updateProperties(String&nbsp;keyname,String&nbsp;keyvalue)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">try</span><span style="border:none;background-color:inherit;">&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;props.load(<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;FileInputStream(profilepath));&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;調用&nbsp;Hashtable&nbsp;的方法&nbsp;put,使用&nbsp;getProperty&nbsp;方法提供並行性。&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;強制要求爲屬性的鍵和值使用字符串。返回值是&nbsp;Hashtable&nbsp;調用&nbsp;put&nbsp;的結果。&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStream&nbsp;fos&nbsp;=&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">new</span><span style="border:none;background-color:inherit;">&nbsp;FileOutputStream(profilepath);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;props.setProperty(keyname,&nbsp;keyvalue);&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;以適合使用&nbsp;load&nbsp;方法加載到&nbsp;Properties&nbsp;表中的格式,&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//&nbsp;將此&nbsp;Properties&nbsp;表中的屬性列表(鍵和元素對)寫入輸出流&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;props.store(fos,&nbsp;<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"Update&nbsp;'"</span><span style="border:none;background-color:inherit;">&nbsp;+&nbsp;keyname&nbsp;+&nbsp;</span><span class="string" style="border:none;color:#FF0000;background-color:inherit;">"'&nbsp;value"</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">catch</span><span style="border:none;background-color:inherit;">&nbsp;(IOException&nbsp;e)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.err.println(<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"屬性文件更新錯誤"</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border:none;color:rgb(0,130,0);background-color:inherit;">//測試代碼&nbsp;</span><span style="border:none;background-color:inherit;">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">public</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">static</span><span style="border:none;background-color:inherit;">&nbsp;</span><span class="keyword" style="border:none;color:#0000FF;font-weight:bold;background-color:inherit;">void</span><span style="border:none;background-color:inherit;">&nbsp;main(String[]&nbsp;args)&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;readValue(<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"mail.properties"</span><span style="border:none;background-color:inherit;">,&nbsp;</span><span class="string" style="border:none;color:#FF0000;background-color:inherit;">"MAIL_SERVER_PASSWORD"</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeProperties(<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"MAIL_SERVER_INCOMING"</span><span style="border:none;background-color:inherit;">,&nbsp;</span><span class="string" style="border:none;color:#FF0000;background-color:inherit;">"327@qq.com"</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string" style="border:none;color:#FF0000;background-color:inherit;">"操做完成"</span><span style="border:none;background-color:inherit;">);&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:inherit;line-height:18px;"> <span style="border:none;color:#000000;background-color:inherit;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li><li style="border-style:none none none solid;border-left-width:3px;border-left-color:rgb(153,153,153);list-style:outside;color:rgb(85,85,85);line-height:18px;background-color:rgb(248,248,248);"> <span style="border:none;color:#000000;background-color:inherit;">}&nbsp;</span></li></ol> </div>java

相關文章
相關標籤/搜索