锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲av不卡一区二区三区,亚洲人成电影网站久久,国产99在线|亚洲http://m.tkk7.com/pdw2009/category/14802.htmlJ2EE鐩稿叧搴旂敤鎶鏈棩蹇?/description>zh-cnFri, 07 Aug 2009 11:25:50 GMTFri, 07 Aug 2009 11:25:50 GMT60Html Parse 鏈浣沖疄璺?/title><link>http://m.tkk7.com/pdw2009/archive/2008/06/19/209125.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Thu, 19 Jun 2008 03:53:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2008/06/19/209125.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/209125.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2008/06/19/209125.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/209125.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/209125.html</trackback:ping><description><![CDATA[<p> </p> 鏈枃杞Щ鍒?a title="http://php.11519.net/5jblog/?p=399" >http://php.11519.net/5jblog/?p=399</a> <img src ="http://m.tkk7.com/pdw2009/aggbug/209125.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2008-06-19 11:53 <a href="http://m.tkk7.com/pdw2009/archive/2008/06/19/209125.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍔犲瘑涓庣紪鐮?/title><link>http://m.tkk7.com/pdw2009/archive/2008/06/19/209121.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Thu, 19 Jun 2008 03:45:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2008/06/19/209121.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/209121.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2008/06/19/209121.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/209121.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/209121.html</trackback:ping><description><![CDATA[<p>杞Щ鍒? <a >http://php.11519.net/5jblog/?p=414</a></p> <img src ="http://m.tkk7.com/pdw2009/aggbug/209121.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2008-06-19 11:45 <a href="http://m.tkk7.com/pdw2009/archive/2008/06/19/209121.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>unicode 緙栫爜杞崲鎴愭眽瀛?/title><link>http://m.tkk7.com/pdw2009/archive/2008/06/19/209119.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Thu, 19 Jun 2008 03:33:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2008/06/19/209119.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/209119.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2008/06/19/209119.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/209119.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/209119.html</trackback:ping><description><![CDATA[     鎽樿: 鎶婃渶榪戝伐浣滀腑鎵鍐欑殑浠g爜璐翠竴涓?浠ュ鍚庣敤,濡傝兘緇欎簣浣犲府鍔╂垜涓囧垎楂樺叴 package com.easylotto.omas.util; import java.util.*; import java.io.*; import org.apache.commons.lang.*; /**  * 鏇挎崲HTMl閲岄潰鐨勫瓧絎?n...  <a href='http://m.tkk7.com/pdw2009/archive/2008/06/19/209119.html'>闃呰鍏ㄦ枃</a><img src ="http://m.tkk7.com/pdw2009/aggbug/209119.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2008-06-19 11:33 <a href="http://m.tkk7.com/pdw2009/archive/2008/06/19/209119.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>JAVA鍜孞AVAC 鍛戒護琛?http://m.tkk7.com/pdw2009/archive/2008/06/12/207413.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Thu, 12 Jun 2008 08:00:00 GMThttp://m.tkk7.com/pdw2009/archive/2008/06/12/207413.htmlhttp://m.tkk7.com/pdw2009/comments/207413.htmlhttp://m.tkk7.com/pdw2009/archive/2008/06/12/207413.html#Feedback0http://m.tkk7.com/pdw2009/comments/commentRss/207413.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/207413.htmlJAVA鍜孞AVAC 鍛戒護琛?/a>
javac鍜宩ava鍛戒護琛屼腑鐨?classpath閫夐」
榪欐槸涓緢鍩虹鐨勯棶棰橈紝浣嗘槸鍥犱負鍩烘湰涓婇兘鏄敤鐜版湁鐨処DE宸ュ叿 鏉ュ紑鍙慾ava紼嬪簭錛屾墍浠ュ緢灝戞湁浜烘剰璇嗗埌榪欎竴鐐廣?br /> javac
-classpath錛岃瀹氳鎼滅儲綾葷殑璺緞錛屽彲浠ユ槸鐩綍錛宩ar鏂囦歡錛寊ip鏂囦歡錛堥噷闈㈤兘鏄痗lass鏂囦歡錛夛紝浼氳鐩栨帀鎵鏈夊湪CLASSPATH閲岄潰鐨勮瀹氥?br /> -sourcepath錛?璁懼畾瑕佹悳绱㈢紪璇戞墍闇java 鏂囦歡鐨勮礬寰勶紝鍙互鏄洰褰曪紝jar鏂囦歡錛寊ip鏂囦歡錛堥噷闈㈤兘鏄痡ava鏂囦歡錛夈?br /> 鎵浠ヤ竴涓畬鏁寸殑javac鍛戒護琛屽簲璇ユ槸榪欐牱鐨勶紝
鍋囪abc.java鍦ㄨ礬寰刢:\src閲岄潰錛屽湪浠諱綍鐨勭洰褰曠殑閮藉彲浠ユ墽琛屼互涓嬪懡浠ゆ潵緙栬瘧銆?br /> javac -classpath c:\classes;c:\jar\abc.jar;c:\zip\abc.zip -sourcepath c:\source\project1\src;c:\source\project2 \lib\src.jar;c:\source\project3\lib\src.zip c:\src\abc.java

琛ㄧず緙栬瘧闇瑕乧:\classed涓嬮潰鐨刢lass鏂囦歡錛宑:\jar\abc.jar閲岄潰鐨刢lass鏂囦歡錛宑:\zip\abc.zip閲岄潰鐨刢lass鏂囦歡
榪橀渶瑕乧:\source\project1\src涓嬮潰鐨勬簮鏂囦歡錛宑:\source\project2 \lib\src.jar閲岄潰鐨勬簮鏂囦歡錛宑:\source\project3\lib\src.zip閲岄潰鐨勬簮鏂囦歡錛?br style="color: rgb(255,0,0)" /> 娉ㄦ剰錛歫ar錛寊ip閲岄潰鐨勬簮鏂囦歡涓嶄細鏈変粈涔堟敼鍔紝鐩綍涓嬬殑婧愭枃浠訛紝鏈夊彲鑳戒細琚噸鏂扮紪璇戙?br /> java
-classpath錛?璁懼畾瑕佹悳绱㈢殑綾葷殑璺緞錛屽彲浠ユ槸鐩綍錛宩ar鏂囦歡錛寊ip鏂囦歡錛堥噷闈㈤兘鏄痗lass鏂囦歡錛夛紝浼氳鐩栨帀鎵鏈夌殑CLASSPATH鐨勮瀹氥?br /> 鐢變簬鎵瑕佹墽琛岀殑綾諱篃鏄鎼滅儲鐨勭被鐨勪竴閮ㄥ垎錛屾墍浠ヤ竴瀹氳鎶婅繖涓被鐨勮礬寰勪篃鏀懼埌-classpath鐨勮緗噷闈€?br /> 琛ㄧ幇鍦紝鍦ㄨ鎵ц鐨勭被鐨勮礬寰勯噷闈㈡墽琛宩ava鏃訛紝涓瀹氳娣誨姞涓婄偣鍙鳳紙.錛夋爣紺烘湰鐩綍涔熻鎼滅儲銆?br />
鍋囪abc.class鍦ㄨ礬寰刢:\src閲岄潰
鍙互鍦ㄤ換浣曡礬寰勪笅鎵ц浠ヤ笅鍛戒護
java -classpath c:\classes;
c:\jar\abc.jar;c:\zip\abc.zip;c:\src abc

闂錛氬鏋渕ain.class灞炰簬c:\jar\abc.jar錛屽茍涓斿湪com.cnblogs.jeffchen榪欎釜鍖呴噷錛岄偅涔堟墽琛宩ava -classpath c:\classes;c:\jar\abc.jar;c:\zip\abc.zip;com.cnblogs.jeffchen.main鍗沖彲錛?浣嗘槸濡傛灉classpath涓寘鍚涓猨ar鍖呭憿錛熷茍涓斿叾浠杍ar鍖呬腑涔熸湁com.cnblogs.jeffchen浼氬彂鐢熶粈涔堟儏鍐碉紵閿欒錛?br />
鍦╳indows涓嬶紝
鏂囦歡璺緞鐨勫垎鍓茬涓哄弽鏂滄潬  \  
綾繪垨鑰卝ava鏂囦歡鍒楄〃鐨勫垎鍓茬涓哄垎鍙?;

鍦╨inux涓?br /> 鏂囦歡璺緞鐨勫垎闅旂浣嶆枩鏉?/
綾繪垨鑰卝ava鏂囦歡鍒楄〃鐨勫垎闅旂涓哄啋鍙?:

涓涓猯inux涓嬬紪璇戝拰榪愯鐨勪緥瀛?br />  /usr/local/java/bin/javac -classpath /tmp/javatest/lib/mail-1.3.3.jar -d /tmp/javatest/bin/ /tmp/javatest/src/jp/co/realseed/Capability.java

/usr/local/java/bin/java -classpath /tmp/javatest/lib/mail-1.3.3.jar:/tmp/javatest/bin/ jp.co.realseed.Capability



]]>
java鍔犲瘑鐩稿叧鎶鏈?/title><link>http://m.tkk7.com/pdw2009/archive/2008/04/15/193046.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Tue, 15 Apr 2008 03:44:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2008/04/15/193046.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/193046.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2008/04/15/193046.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/193046.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/193046.html</trackback:ping><description><![CDATA[鍓嶆鏃墮棿闇瑕佺敤鍒拌繖鏂歸潰鐨勬妧鏈?鍐欎簡鍑犱釜渚嬪瓙,涓嶅姞鏂囧瓧璇存槑,鍙創浠g爜<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #0000ff">package</span><span style="color: #000000"> demo.encrypt;<br /> <br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.UnsupportedEncodingException;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.MessageDigest;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.NoSuchAlgorithmException;<br /> <br /> </span><span style="color: #008000">/**</span><span style="color: #008000"><br />  * <br />  * 鎽樿鍔犲瘑銆傛楠屼俊鎭畬鏁存?nbsp;鐩墠騫挎硾浣跨敤鐨勭畻娉曟湁MD4銆丮D5銆丼HA-1<br />  * </span><span style="color: #808080">@author</span><span style="color: #008000"> peidw 2008-03-02<br />  *<br />  </span><span style="color: #008000">*/</span><span style="color: #000000"><br /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> MessageDigestExample {<br /> </span><span style="color: #008000">/**</span><span style="color: #008000"><br />  * 淇℃伅鎽樿瀹屾暣鎬у姞瀵?br />  * <br />  </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     <br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * 鍗曚竴鎽樿綆楁硶錛屼笉浣跨敤瀵嗙爜<br />      * </span><span style="color: #808080">@param</span><span style="color: #008000"> args<br />      * </span><span style="color: #808080">@throws</span><span style="color: #008000"> UnsupportedEncodingException <br />      * </span><span style="color: #808080">@throws</span><span style="color: #008000"> NoSuchAlgorithmException <br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> UnsupportedEncodingException, NoSuchAlgorithmException {<br />         String str</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">www.17lotto.com</span><span style="color: #000000">"</span><span style="color: #000000">;  </span><span style="color: #008000">//</span><span style="color: #008000">瑕佸姞瀵嗙殑瀛楃涓?/span><span style="color: #008000"><br /> </span><span style="color: #000000">        </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] bstr</span><span style="color: #000000">=</span><span style="color: #000000">str.getBytes(</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         MessageDigest messageDigest</span><span style="color: #000000">=</span><span style="color: #000000">MessageDigest.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">SHA-1</span><span style="color: #000000">"</span><span style="color: #000000">); </span><span style="color: #008000">//</span><span style="color: #008000">鑾峰彇綆楁硶</span><span style="color: #008000"><br /> </span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">messageDigest.getProvider().getInfo());<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">鍔犲瘑鍓?\n </span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(bstr));<br />         <br />         messageDigest.update(bstr);<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\n鍔犲瘑鍚庣粨鏋?</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(messageDigest.digest(),</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">));<br /> <br />     }<br /> <br /> }<br /> </span></div> <br /> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #0000ff">package</span><span style="color: #000000"> demo.encrypt;<br /> <br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.</span><span style="color: #000000">*</span><span style="color: #000000">;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.Key;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.NoSuchAlgorithmException;<br /> <br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> javax.crypto.Cipher;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> javax.crypto.KeyGenerator;<br /> <br /> </span><span style="color: #008000">/**</span><span style="color: #008000"><br />  * 縐侀挜鍔犲瘑錛屼篃縐板縐版у瘑鐮侊紝鍔?瑙e瘑鍙屾柟鍏變韓鍚屼竴瀵嗛挜<br />  * <br />  * </span><span style="color: #808080">@author</span><span style="color: #008000"> peidw<br />  *<br />  </span><span style="color: #008000">*/</span><span style="color: #000000"><br /> <br /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> PrivateExample {<br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * 鍔犲繀瑙e瘑渚嬪瓙<br />      * </span><span style="color: #808080">@throws</span><span style="color: #008000"> Exception<br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> deendemo()</span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception{<br />         String str</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">www.17lotto.com</span><span style="color: #000000">"</span><span style="color: #000000">;  </span><span style="color: #008000">//</span><span style="color: #008000">瑕佸姞瀵嗙殑瀛楃涓?/span><span style="color: #008000"><br /> </span><span style="color: #000000">        </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] bstr</span><span style="color: #000000">=</span><span style="color: #000000">str.getBytes(</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         </span><span style="color: #008000">//</span><span style="color: #008000">浜х敓瀵嗛挜</span><span style="color: #008000"><br /> </span><span style="color: #000000">        KeyGenerator keyGen</span><span style="color: #000000">=</span><span style="color: #000000">KeyGenerator.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">AES</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         keyGen.init(</span><span style="color: #000000">128</span><span style="color: #000000">);<br />         <br />         Key key</span><span style="color: #000000">=</span><span style="color: #000000">keyGen.generateKey();<br />         </span><span style="color: #008000">//</span><span style="color: #008000">瀵嗛挜淇濆瓨</span><span style="color: #008000"><br /> </span><span style="color: #000000">        File fkey</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> File(</span><span style="color: #000000">"</span><span style="color: #000000">f:\\key.obj</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         OutputStream os</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(fkey);<br />         os.write(key.getEncoded());<br />         os.flush();<br />         os.close();<br />         </span><span style="color: #008000">//</span><span style="color: #008000">瀵嗛挜淇濆瓨闂<br />         <br />         </span><span style="color: #008000">//</span><span style="color: #008000">鑾峰緱涓涓閳呭姞瀵嗙被Cipher錛孍CB鏄姞瀵嗘柟寮忥紝PKCS5Padding鏄~鍏呮柟娉?/span><span style="color: #008000"><br /> </span><span style="color: #000000">        Cipher cipher</span><span style="color: #000000">=</span><span style="color: #000000">Cipher.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">AES/ECB/PKCS5Padding</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">cipher.getProvider().getInfo());<br />         <br />         </span><span style="color: #008000">//</span><span style="color: #008000">浣跨敤縐侀垍鍔犲瘑</span><span style="color: #008000"><br /> </span><span style="color: #000000">        cipher.init(Cipher.ENCRYPT_MODE,key);<br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] cipherText</span><span style="color: #000000">=</span><span style="color: #000000">cipher.doFinal(bstr);<br />         </span><span style="color: #008000">//</span><span style="color: #008000">瀵嗘枃淇濆瓨</span><span style="color: #008000"><br /> </span><span style="color: #000000">        File cryptograph</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> File(</span><span style="color: #000000">"</span><span style="color: #000000">f:\\cryptograph.obj</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         OutputStream cos</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(cryptograph);<br />         cos.write(cipherText);<br />         cos.flush();<br />         cos.close();<br />         <br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Finish encryption:</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(cipherText,</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">));<br /> <br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\nStart decryption:</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         cipher.init(Cipher.DECRYPT_MODE,key);<br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] newPlainText</span><span style="color: #000000">=</span><span style="color: #000000">cipher.doFinal(cipherText);<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Finish decryption:</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <br />         System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(newPlainText,</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">));<br />         <br />     }<br />     <br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * 浠庢枃浠跺姞杞藉瘑閽ュ拰瀵嗘枃榪涜瑙e瘑渚嬪瓙(鏂癹dk涓嶆噦鎬庝箞鍔犺澆)<br />      * </span><span style="color: #808080">@throws</span><span style="color: #008000"> Exception<br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> decryptionFromFile()</span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception{<br />         KeyGenerator keyGen</span><span style="color: #000000">=</span><span style="color: #000000">KeyGenerator.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">AES</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         <br />     }<br />     <br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * </span><span style="color: #808080">@param</span><span style="color: #008000"> args<br />      * </span><span style="color: #808080">@throws</span><span style="color: #008000"> Exception <br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception {<br />         PrivateExample pe</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> PrivateExample();<br />         pe.deendemo();<br />     }<br /> <br /> }<br /> </span></div> <br /> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #0000ff">package</span><span style="color: #000000"> demo.encrypt;<br /> <br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.</span><span style="color: #000000">*</span><span style="color: #000000">;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.KeyFactory;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.KeyPair;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.KeyPairGenerator;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.PrivateKey;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.PublicKey;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.spec.PKCS8EncodedKeySpec;<br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.spec.X509EncodedKeySpec;<br /> <br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> javax.crypto.Cipher;<br /> <br /> </span><span style="color: #008000">/**</span><span style="color: #008000"><br />  *  闈炲縐版у姞瀵嗭紝涔熷彨鍏挜鍔犲瘑 浜у紑涓や釜瀵嗛挜錛堢閽ワ紝鍏挜錛夌閽ュ姞瀵嗗彧鏈夊叕閽ユ墠鑳借В鏍鳳紝鍚屾椂鍏挜鍔犲瘑鍙湁縐侀挜鑳借В寮.<br />  *  鐩墠JDK5鎻愪緵鐨凴SA綆楁硶<br />  * </span><span style="color: #808080">@author</span><span style="color: #008000"> peidw<br />  *<br />  </span><span style="color: #008000">*/</span><span style="color: #000000"><br /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> PublicExample {<br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * 鍔犲瘑瑙e瘑渚嬪瓙<br />      * </span><span style="color: #808080">@throws</span><span style="color: #008000"> Exception<br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> deenDemo()</span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception{<br />         String str</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">www.17lotto.com</span><span style="color: #000000">"</span><span style="color: #000000">;<br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000"> bstr[]</span><span style="color: #000000">=</span><span style="color: #000000">str.getBytes(</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         </span><span style="color: #008000">//</span><span style="color: #008000">鏋勬垚涓涓猂SA瀵嗛挜</span><span style="color: #008000"><br /> </span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\nStart generating RSA key</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         KeyPairGenerator keyGen</span><span style="color: #000000">=</span><span style="color: #000000">KeyPairGenerator.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">RSA</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         keyGen.initialize(</span><span style="color: #000000">1024</span><span style="color: #000000">);<br />         KeyPair key</span><span style="color: #000000">=</span><span style="color: #000000">keyGen.generateKeyPair();<br />         </span><span style="color: #008000">//</span><span style="color: #008000">淇濆瓨鍏?縐佸瘑閽?/span><span style="color: #008000"><br /> </span><span style="color: #000000">        File pubfile</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> File(</span><span style="color: #000000">"</span><span style="color: #000000">f:\\public.dat</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         File prifile</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> File(</span><span style="color: #000000">"</span><span style="color: #000000">f:\\private.dat</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         OutputStream pubos</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(pubfile);<br />         OutputStream prios</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(prifile);<br />         pubos.write(key.getPublic().getEncoded());<br />         prios.write(key.getPrivate().getEncoded());<br />         pubos.flush();<br />         prios.flush();<br />         pubos.close();<br />         prios.close();<br />         <br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Finish generating RSA key</span><span style="color: #000000">"</span><span style="color: #000000">);        <br />         </span><span style="color: #008000">//</span><span style="color: #008000">鑾峰緱涓涓猂SA鐨凜ipher綾伙紝浣跨敤鍏垍鍔犲瘑</span><span style="color: #008000"><br /> </span><span style="color: #000000">        Cipher cipher</span><span style="color: #000000">=</span><span style="color: #000000">Cipher.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">RSA/ECB/PKCS1Padding</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">cipher.getProvider().getInfo());<br /> <br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\nStart encryption</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         cipher.init(Cipher.ENCRYPT_MODE,key.getPublic());<br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] cipherText</span><span style="color: #000000">=</span><span style="color: #000000">cipher.doFinal(bstr);<br />         <br />         File pub_cryptograph</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> File(</span><span style="color: #000000">"</span><span style="color: #000000">f:\\pub_cryptograph.dat</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         OutputStream os</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(pub_cryptograph);<br />         os.write(cipherText);<br />         os.flush();<br />         os.close();<br />         <br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Finish encryption:</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(cipherText,</span><span style="color: #000000">"</span><span style="color: #000000">UTF8</span><span style="color: #000000">"</span><span style="color: #000000">));        <br />         </span><span style="color: #008000">//</span><span style="color: #008000">浣跨敤縐侀垍瑙e瘑</span><span style="color: #008000"><br /> </span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\nStart decryption</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         cipher.init(Cipher.DECRYPT_MODE,key.getPrivate());<br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] newPlainText</span><span style="color: #000000">=</span><span style="color: #000000">cipher.doFinal(cipherText);<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Finish decryption:</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(newPlainText,</span><span style="color: #000000">"</span><span style="color: #000000">UTF8</span><span style="color: #000000">"</span><span style="color: #000000">));<br />         <br />     }<br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * 鍔犺縐侀挜錛岃В瀵嗗叕閽ュ姞瀵嗙殑鏂囩殑鏂囦歡<br />      * </span><span style="color: #808080">@throws</span><span style="color: #008000"> Exception<br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> fromfielEnDeDemo()</span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception{<br />         File prifile</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> File(</span><span style="color: #000000">"</span><span style="color: #000000">f:\\private.dat</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         FileInputStream fsprivateKey </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> FileInputStream(prifile); <br />         BufferedInputStream bfsprivateKey </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> BufferedInputStream(fsprivateKey); <br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] byteprivateKey </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> </span><span style="color: #0000ff">byte</span><span style="color: #000000">[bfsprivateKey.available()]; <br />         bfsprivateKey.read(byteprivateKey); <br />         bfsprivateKey.close();<br />         </span><span style="color: #008000">//</span><span style="color: #008000">X509EncodedKeySpec priKeySpec = new X509EncodedKeySpec(byteprivateKey);  鍏挜鍔犺澆娉?/span><span style="color: #008000"><br /> </span><span style="color: #000000">        PKCS8EncodedKeySpec priKeySpec </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> PKCS8EncodedKeySpec(byteprivateKey);  </span><span style="color: #008000">//</span><span style="color: #008000">縐侀挜鍔犺澆</span><span style="color: #008000"><br /> </span><span style="color: #000000">        <br />         KeyFactory keyFactory </span><span style="color: #000000">=</span><span style="color: #000000"> KeyFactory.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">RSA</span><span style="color: #000000">"</span><span style="color: #000000">); <br />         PrivateKey priKey </span><span style="color: #000000">=</span><span style="color: #000000"> keyFactory.generatePrivate(priKeySpec); <br />         System.out.println(priKey.getFormat());<br />         <br />         Cipher cipher</span><span style="color: #000000">=</span><span style="color: #000000">Cipher.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">RSA/ECB/PKCS1Padding</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         cipher.init(Cipher.DECRYPT_MODE,priKey);<br />         <br />         File pubcryptographfile</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> File(</span><span style="color: #000000">"</span><span style="color: #000000">f:\\pub_cryptograph.dat</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         FileInputStream pubcis </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> FileInputStream(pubcryptographfile);     <br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000"> cstr[]</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> </span><span style="color: #0000ff">byte</span><span style="color: #000000">[pubcis.available()];<br />         pubcis.read(cstr);<br />         pubcis.close();<br />         <br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] newPlainText</span><span style="color: #000000">=</span><span style="color: #000000">cipher.doFinal(cstr);<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Finish decryption:</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(newPlainText,</span><span style="color: #000000">"</span><span style="color: #000000">UTF8</span><span style="color: #000000">"</span><span style="color: #000000">));        <br />     }<br />     <br />     <br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * </span><span style="color: #808080">@param</span><span style="color: #008000"> args<br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception{<br />         </span><span style="color: #008000">//</span><span style="color: #008000"> TODO Auto-generated method stub</span><span style="color: #008000"><br /> </span><span style="color: #000000">        PublicExample pe</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> PublicExample();<br />         pe.fromfielEnDeDemo();<br />     }<br /> <br /> }<br /> </span></div> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #0000ff">package</span><span style="color: #000000"> demo.encrypt;<br /> <br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.security.</span><span style="color: #000000">*</span><span style="color: #000000">;<br /> <br /> </span><span style="color: #008000">/**</span><span style="color: #008000"><br />  * <p>鏁板瓧絳懼悕</p><br />  * <pre><br />  *   浣跨敤RSA縐侀挜瀵逛俊鎭憳瑕佺鍚嶏紝鐒跺悗鐢ㄥ叕閽ヨ繘琛岃В瀵?br />  * </pre><br />  * </span><span style="color: #808080">@author</span><span style="color: #008000"> peidw<br />  *<br />  </span><span style="color: #008000">*/</span><span style="color: #000000"><br /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> DigitalSignature2Example {<br />     <br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> test () </span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception {<br />         String str</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">www.17lotto.com</span><span style="color: #000000">"</span><span style="color: #000000">;<br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] bstr</span><span style="color: #000000">=</span><span style="color: #000000">str.getBytes(</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         </span><span style="color: #008000">//</span><span style="color: #008000">褰㈡垚RSA鍏閽ュ</span><span style="color: #008000"><br /> </span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\nStart generating RSA key</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         KeyPairGenerator keyGen</span><span style="color: #000000">=</span><span style="color: #000000">KeyPairGenerator.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">RSA</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         keyGen.initialize(</span><span style="color: #000000">1024</span><span style="color: #000000">);<br />         KeyPair key</span><span style="color: #000000">=</span><span style="color: #000000">keyGen.generateKeyPair();<br />         <br />         Signature sig</span><span style="color: #000000">=</span><span style="color: #000000">Signature.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">SHA1WithRSA</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         sig.initSign(key.getPrivate());<br />         sig.update(bstr);<br />         </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] signature</span><span style="color: #000000">=</span><span style="color: #000000">sig.sign();<br />         System.out.println(sig.getProvider().getInfo());<br />         System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\nSignature:</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000"> String(signature,</span><span style="color: #000000">"</span><span style="color: #000000">utf-8</span><span style="color: #000000">"</span><span style="color: #000000">));<br /> <br />         </span><span style="color: #008000">//</span><span style="color: #008000">浣跨敤鍏垍楠岃瘉</span><span style="color: #008000"><br /> </span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">\nStart signature verification</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         sig.initVerify(key.getPublic());<br />         sig.update(bstr);<br />         </span><span style="color: #0000ff">try</span><span style="color: #000000">{<br />             </span><span style="color: #0000ff">if</span><span style="color: #000000">(sig.verify(signature)){<br />               System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Signature verified</span><span style="color: #000000">"</span><span style="color: #000000">);<br />             }</span><span style="color: #0000ff">else</span><span style="color: #000000"> System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Signature failed</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         }</span><span style="color: #0000ff">catch</span><span style="color: #000000">(SignatureException e){<br />             System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Signature failed</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         }        <br /> <br />         <br />     }<br />     <br />     </span><span style="color: #008000">/**</span><span style="color: #008000"><br />      * </span><span style="color: #808080">@param</span><span style="color: #008000"> args<br />      </span><span style="color: #008000">*/</span><span style="color: #000000"><br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) {<br />         </span><span style="color: #008000">//</span><span style="color: #008000"> TODO Auto-generated method stub</span><span style="color: #008000"><br /> </span><span style="color: #000000"><br />     }<br /> <br /> }<br /> </span></div> <img src ="http://m.tkk7.com/pdw2009/aggbug/193046.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2008-04-15 11:44 <a href="http://m.tkk7.com/pdw2009/archive/2008/04/15/193046.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>灝哢nicode 鐮?瀛楃涓?杞崲鎴愭眽瀛?/title><link>http://m.tkk7.com/pdw2009/archive/2008/02/18/180485.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Mon, 18 Feb 2008 08:18:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2008/02/18/180485.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/180485.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2008/02/18/180485.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/180485.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/180485.html</trackback:ping><description><![CDATA[<p><br /> 渚嬪瓙浠g爜濡傜浉,鍘熺悊鎴戣繕娌″紕鏄庣櫧<br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #0000ff">package</span><span style="color: #000000"> example;<br /> <br /> </span><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.UnsupportedEncodingException;<br /> </span><span style="color: #008000">/**</span><span style="color: #008000"><br />  * Unicode 鐮佽漿鎴愭眽瀛?br />  * </span><span style="color: #808080">@author</span><span style="color: #008000"> peidw<br />  *<br />  </span><span style="color: #008000">*/</span><span style="color: #000000"><br /> <br /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> CodeFormTest {<br />     </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String args[]) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> UnsupportedEncodingException{<br />         String a</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">开始兑奖</span><span style="color: #000000">"</span><span style="color: #000000">;<br />         String str </span><span style="color: #000000">=</span><span style="color: #000000"> a.replaceAll(</span><span style="color: #000000">"</span><span style="color: #000000">&#</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">).replaceAll(</span><span style="color: #000000">"</span><span style="color: #000000">;</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">""</span><span style="color: #000000">);<br />         String [] s2 </span><span style="color: #000000">=</span><span style="color: #000000"> str.split(</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">);<br />         String s1 </span><span style="color: #000000">=</span><span style="color: #000000">""</span><span style="color: #000000">;<br />         System.out.println(s2.length);<br />         </span><span style="color: #0000ff">for</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000"> i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000"><</span><span style="color: #000000">s2.length;i</span><span style="color: #000000">++</span><span style="color: #000000">){<br />             </span><span style="color: #0000ff">int</span><span style="color: #000000"> v </span><span style="color: #000000">=</span><span style="color: #000000"> Integer.parseInt(s2[i],</span><span style="color: #000000">10</span><span style="color: #000000">);<br />             s1</span><span style="color: #000000">=</span><span style="color: #000000">s1</span><span style="color: #000000">+</span><span style="color: #000000">(</span><span style="color: #0000ff">char</span><span style="color: #000000">)v;<br />         }<br />         System.out.println(s1);<br />     }<br /> }<br /> </span></div> <img src ="http://m.tkk7.com/pdw2009/aggbug/180485.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2008-02-18 16:18 <a href="http://m.tkk7.com/pdw2009/archive/2008/02/18/180485.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>java api鎻愪緵鐨勬鍒欒〃杈懼紡http://m.tkk7.com/pdw2009/archive/2008/01/21/176744.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Mon, 21 Jan 2008 05:57:00 GMThttp://m.tkk7.com/pdw2009/archive/2008/01/21/176744.htmlhttp://m.tkk7.com/pdw2009/comments/176744.htmlhttp://m.tkk7.com/pdw2009/archive/2008/01/21/176744.html#Feedback0http://m.tkk7.com/pdw2009/comments/commentRss/176744.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/176744.html 鍦╦ava涓鍒欒繍綆椾富瑕佺敱涓夐儴鍒嗘瀯鎴?

1銆佹ā寮廝arttern

2銆佺煡閰嶅櫒Matcher

3銆佽緭鍏ュ瓧絎︿覆

鍙傝冨涓嬩緥瀛愬拰鍒殑blog
package example;
import java.util.regex.*;

public class RegexDemo {

    
/**
     * 
@param args
     
*/
    
public static void main(String[] args) {
        
// TODO Auto-generated method stub
        String str="ccdewps kkikk";
        String regEx
="a|f";
        Pattern  p
=Pattern.compile(regEx,Pattern.CASE_INSENSITIVE);
        Matcher m
=p.matcher(str);
        
boolean result=m.find();
        System.out.println(result);
        
//鏇挎崲
        str="ababccded,ab ,love ";
        regEx
="a+";
        p
=Pattern.compile(regEx);
        m
=p.matcher(str);
        String s
=m.replaceAll("--"); //""琛ㄧず鍒犻櫎
        System.out.println(s);
        regEx
="(love)";
        p
=Pattern.compile(regEx);
        m
=p.matcher(str);
        String s1
=m.replaceAll("&"); //""琛ㄧず鍒犻櫎
        System.out.println(s1);
        System.out.println(m.find());
        p
=Pattern.compile("c.e");
        m
=p.matcher(str);
        System.out.println(m.find());
        System.out.println(m.replaceFirst(
"鍛靛懙,姝e垯琛ㄨ揪寮?/span>"));
    }

}

 

榪欑瘒浠嬬粛java 姝e垯鐨刡log鍐欏緱涓嶉敊錛岀粏蹇冪湅涓閬嶅氨鑳藉紕鎳備釜澶ф
http://blog.csdn.net/ambitiontan/archive/2005/12/21/558195.aspx

鏈鍚庡垏璁版鍒欑殑鐩殑錛氬瀛楃涓叉琛岋紝鏌ユ壘鍖歸厤銆佹浛鎹€佸垹闄ょ瓑宸ヤ綔銆?/p>

 



]]>
java璇誨彇璧勬簮鏂囦歡http://m.tkk7.com/pdw2009/archive/2007/10/11/152182.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Thu, 11 Oct 2007 15:54:00 GMThttp://m.tkk7.com/pdw2009/archive/2007/10/11/152182.htmlhttp://m.tkk7.com/pdw2009/comments/152182.htmlhttp://m.tkk7.com/pdw2009/archive/2007/10/11/152182.html#Feedback2http://m.tkk7.com/pdw2009/comments/commentRss/152182.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/152182.html濡備綍璇誨彇璧勬簮鏂囦歡錛?br /> 錛堜竴錛?br /> Properties props = new Properties();   
props.load(new FileInputStream("db.properties"));
錛堜簩錛?br /> blog.properties鏂囦歡濡備笅
dbdriver=oracle.jdbc.driver.OracleDriver
dburl=jdbc:oracle:thin:@127.0.0.1:1521:ora92
dbuser=blog
dbpwd=blog
--------------
public class Config {
  public Config() {
    this.initDBConfig();
  }
  public String DBdriver;
  public String DBuser;
  public String DBpwd;
  public String DBurl;
  private void initDBConfig() {
    try {
      ResourceBundle bundle = ResourceBundle.getBundle("blog");
      DBdriver = bundle.getString("dbdriver");
      DBurl = bundle.getString("dburl");
      DBuser = bundle.getString("dbuser");
      DBpwd = bundle.getString("dbpwd");
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}
----------------
public class DAO {
  public DAO() {
  }
  public Connection getConnection() {
    Connection conn = null;
    Config config = new Config();
    String DBdriver = config.DBdriver;
    String DBuser = config.DBuser;
    String DBpwd = config.DBpwd;
    String DBurl = config.DBurl;
    try {
      Class.forName(DBdriver);
      conn = DriverManager.getConnection(DBurl, DBuser, DBpwd);
    }
    catch (Exception ex) {
      System.out.println("********************");
      System.out.println("涓嶈兘寰楀埌鏁版嵁搴撹繛鎺?);
      System.out.println("DBdriver: " + DBdriver);
      System.out.println("DBuser: " + DBuser);
      System.out.println("DBpwd: " + DBpwd);
      System.out.println("DBurl: " + DBurl);
      ex.printStackTrace();
    }
    return conn;
  }
}
錛堜笁錛?br />  Properties props=new Properties();
 props.load(BugFactory.class.getResourceAsStream("xx.properties"));
 String name = props.getPropery("xxxx");
 姝ゆ椂xx.properties搴旇涓庤綾繪斁鍦ㄥ悓涓涓洰褰?
錛堝洓錛?br />  ResourceBundle res = ResourceBundle.getBundle("yy.properties");
 String name = res.getString("yyyy");
 yy.properties搴旀斁鍦?WEB-INF/classes鐩綍
錛堜簲錛?br /> 濡傛灉浣犺繖涓狟ean鎵撳寘鐨勮瘽錛屽氨鎶婅繖涓枃浠舵斁鍦ㄥ寘鍐呫?/div>
鎴戜竴鑸槸榪欐牱鍐欑殑
Properties prop = new Properties();
try
{
 InputStream is = getClass().getResourceAsStream("db.properties");
 prop.load(is);
 if(is!=null)
    is.close();
}
鍙︼細
props.load(new FileInputStream("db.properties")); 鏄鍙栧綋鍓嶇洰褰曠殑db.properties鏂囦歡
getClass.getResourceAsStream("db.properties"); 鏄鍙栧綋鍓嶇被鎵鍦ㄤ綅緗竴璧風殑db.properties鏂囦歡
getClass.getResourceAsStream("/db.properties"); 鏄鍙朇lassPath鐨勬牴鐨刣b.properties鏂囦歡,娉ㄦ剰ClassPath濡傛灉鏄涓礬寰勬垨鑰卝ar鏂囦歡鐨?鍙鍦ㄤ換鎰忎竴涓礬寰勭洰褰曚笅鎴栬卝ar鏂囦歡閲岀殑鏍逛笅閮藉彲浠?濡傛灉瀛樺湪浜庡涓礬寰勪笅鐨勮瘽,鎸夌収ClassPath涓殑鍏堝悗欏哄簭,浣跨敤鍏堟壘鍒扮殑,鍏朵綑蹇界暐.


]]>javax.mail浣跨敤渚嬪瓙http://m.tkk7.com/pdw2009/archive/2007/10/08/151180.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Mon, 08 Oct 2007 14:40:00 GMThttp://m.tkk7.com/pdw2009/archive/2007/10/08/151180.htmlhttp://m.tkk7.com/pdw2009/comments/151180.htmlhttp://m.tkk7.com/pdw2009/archive/2007/10/08/151180.html#Feedback6http://m.tkk7.com/pdw2009/comments/commentRss/151180.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/151180.html闃呰鍏ㄦ枃

]]>
jdk5澶氱嚎紼?杞?http://m.tkk7.com/pdw2009/archive/2007/09/05/142835.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Wed, 05 Sep 2007 02:51:00 GMThttp://m.tkk7.com/pdw2009/archive/2007/09/05/142835.htmlhttp://m.tkk7.com/pdw2009/comments/142835.htmlhttp://m.tkk7.com/pdw2009/archive/2007/09/05/142835.html#Feedback5http://m.tkk7.com/pdw2009/comments/commentRss/142835.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/142835.html  璇ユ枃杞Щ鑷?nbsp; http://php.11519.net/5jblog/?p=401



]]>
java綾誨弽灝勪緥瀛?/title><link>http://m.tkk7.com/pdw2009/archive/2007/08/29/141077.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Wed, 29 Aug 2007 12:47:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2007/08/29/141077.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/141077.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2007/08/29/141077.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/141077.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/141077.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> util;<br><br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.lang.reflect.Field;<br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.lang.reflect.Method;<br><br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> test.web.example.PP;<br></span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br> * <br> * </span><span style="COLOR: #808080">@author</span><span style="COLOR: #008000"> peidw<br> *<br> </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Reflection {<br>    <br>    </span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br>     * 鍙栧緱鍙傛暟瀵硅薄涓殑鍏叡灞炴?br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> obj<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> fieldname<br>     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br>     * </span><span style="COLOR: #808080">@throws</span><span style="COLOR: #008000"> Exception<br>     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object getProperty(Object obj,String fieldname)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        Object result</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br>        Class objClass</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">obj.getClass();<br>        Field field</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">objClass.getField(fieldname);<br>        result</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">field.get(obj);<br>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> result;<br>    }<br>    </span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br>     * 鑾峰緱鏌愮被鐨勯潤鎬佸睘鎬?br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> className<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> fieldName<br>     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br>     * </span><span style="COLOR: #808080">@throws</span><span style="COLOR: #008000"> Exception<br>     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object getStaticProperty(String className,String fieldName)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        Class cls</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Class.forName(className);<br>        Field field</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cls.getField(fieldName);<br>        Object provalue</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">field.get(cls);<br>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> provalue;<br>    }<br>    </span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br>     * 鑾峰彇鍙傛暟瀵硅薄鐨勫睘鎬у?br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> obj<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> propertyName<br>     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br>     * </span><span style="COLOR: #808080">@throws</span><span style="COLOR: #008000"> Exception<br>     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object getPrivatePropertyValue(Object obj,String propertyName)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        Class cls</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">obj.getClass();<br>        Field field</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cls.getDeclaredField(propertyName);<br>        field.setAccessible(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br>        Object retvalue</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">field.get(obj);<br>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> retvalue;<br>    }<br>    <br>    </span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br>     * 鎵ц鏌愬璞$殑鏂規硶<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> owner<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> methodName<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> args<br>     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br>     * </span><span style="COLOR: #808080">@throws</span><span style="COLOR: #008000"> Exception<br>     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object invokeMethod(Object owner,String methodName,Object[] args)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        Class cls</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">owner.getClass();<br>        Class[] argclass</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[args.length];<br>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">argclass.length;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">j;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>            argclass[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">args[i].getClass();<br>        }<br>        Method method</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cls.getMethod(methodName,argclass);<br>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> method.invoke(owner, args);<br>    }<br>    <br>    </span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br>     * 鎵ц闈欐佺被鐨勬柟娉?br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> className<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> methodName<br>     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> args<br>     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br>     * </span><span style="COLOR: #808080">@throws</span><span style="COLOR: #008000"> Exception<br>     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object invokeStaticMethod(String className,String methodName,Object[] args)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        Class cls</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Class.forName(className);<br>        Class[] argclass</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[args.length];<br>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">argclass.length;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">j;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>            argclass[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">args[i].getClass();<br>        }<br>        Method method</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cls.getMethod(methodName,argclass);<br>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> method.invoke(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">, args);<br>    }<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object newInstance(String className,Object[] args)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        Class clss</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Class.forName(className);<br>    <br>        Class[] argclass</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[args.length];<br>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">argclass.length;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">j;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>            argclass[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">args[i].getClass();<br>        }<br>        java.lang.reflect.Constructor cons</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">clss.getConstructor(argclass);<br>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> cons.newInstance();<br>    }<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> main(String[] args)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        Reflection rl</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Reflection();<br>        PP p</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> PP();<br>        rl.getPrivatePropertyValue(p,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">aname</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>    }<br>}<br></span></div> 嫻嬭瘯綾?br> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> test.web.example;<br><br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> org.junit.Assert.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br><br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.junit.Before;<br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.junit.Test;<br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.junit.Assert.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> util.Reflection;<br><br></span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br> * <br> * </span><span style="COLOR: #808080">@author</span><span style="COLOR: #008000"> peidw<br> *<br> </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> ReflectionTest {<br>    <br>    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> PP pp</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br>    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> Reflection reflection</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br>    @Before<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setUp() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception {<br>        reflection</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Reflection();<br>        pp</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> PP();<br>        <br>    }<br><br>    @Test<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testGetProperty() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        System.out.println(pp);<br>        System.out.println(reflection);<br>        System.out.println(reflection.getProperty(pp, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">address</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br>        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">assertEquals(reflection.getProperty(pp, "address"), null);</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">        <br>    }<br><br>    @Test<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testGetStaticProperty()</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        assertEquals(reflection.getStaticProperty(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">test.web.example.PP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">),</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">love you</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>    }<br><br>    @Test<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testGetPrivatePropertyValue() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        assertEquals(reflection.getPrivatePropertyValue(pp, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">aname</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">),</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br>    }<br><br>    @Test<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testInvokeMethod() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        assertEquals(reflection.invokeMethod(pp, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">setAddress</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">鍚堟鄲瑗垮満闀?/span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">}),</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br>        assertEquals(reflection.getProperty(pp, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">address</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">), </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">鍚堟鄲瑗垮満闀?/span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>    }<br><br>    @Test<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testInvokeStaticMethod()</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception {<br>        assertEquals(reflection.invokeStaticMethod(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">test.web.example.PP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">changeCount</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">80</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">}),</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br>        assertEquals(reflection.getStaticProperty(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">test.web.example.PP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">),</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">80</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>    }<br><br>    @Test<br>    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testNewInstance() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br>        <br>        Object vpp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">reflection.newInstance(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">test.web.example.PP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">peidw</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">騫垮窞</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">});<br>        org.junit.Assert.assertNotNull(vpp);<br>        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">assertEquals(reflection.getPrivatePropertyValue(vpp,"aname"),"peidw");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">    }<br><br><br><br>}<br></span></div> <img src ="http://m.tkk7.com/pdw2009/aggbug/141077.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2007-08-29 20:47 <a href="http://m.tkk7.com/pdw2009/archive/2007/08/29/141077.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>itext緇忛獙鎬葷粨( 杞?http://m.tkk7.com/pdw2009/archive/2007/02/28/101162.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Wed, 28 Feb 2007 08:02:00 GMThttp://m.tkk7.com/pdw2009/archive/2007/02/28/101162.htmlhttp://m.tkk7.com/pdw2009/comments/101162.htmlhttp://m.tkk7.com/pdw2009/archive/2007/02/28/101162.html#Feedback0http://m.tkk7.com/pdw2009/comments/commentRss/101162.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/101162.html
iText鏄竴涓瘮杈冨簳灞傜殑pdf搴擄紝寰堝欏圭洰鐨刾df鎿嶄綔閮芥槸浠ュ畠涓哄熀紜鐨勩傚儚spring錛屼互鍙婂彟涓涓瘮杈冩湁鍚嶇殑鎶ヨ〃宸ュ叿jasperreports銆傜畝鍗曠殑pdf鎶ヨ〃杈撳嚭鐢ㄥ畠姣旇緝鍚堥傦紝姣旇緝澶嶆潅鐨勮瘽浣跨敤璧鋒潵灝辨瘮杈冨洶闅句簡錛屼綘瑕佹墜宸ョ紪鍐欏お澶氱殑浠g爜銆?br />
姣旇緝濂界殑鏄痠Text緗戠珯涓婃彁渚涚浉褰撳鐨勭ず渚嬩唬鐮侊紝姣旇緝瀹規槗鍏ラ棬銆傛垜榪欓噷鍙涓浜涘湪瀹冪殑鏂囨。閲屽茍娌℃湁鐩存帴璁插埌鐨勪笢瑗褲?br />
1 鍏充簬Document

Document鐨勫嚑縐嶆瀯閫犲嚱鏁幫細
public Document();
public Document(Rectangle pageSize);
public Document(Rectangle pageSize,
int marginLeft,
int marginRight,
int marginTop,
int marginBottom);
涓嬮潰涓ょ姣旇緝鏈夌敤錛屽鏋滄槸浣犳兂瀹氫箟綰稿紶澶у皬鍜岃竟緙樼殑鏃跺欍傚浜嶮argin錛宨Text涓婃彁鍒扳淵ou can also change the margins while you are adding content. Note that the changes will only be noticed on the NEXT page. If you want the margins mirrored (odd and even pages), you can do this with this method: setMarginMirroring(true). 鈥濅笉榪囷紝瀵逛簬table浼間箮騫朵笉濂戒嬌銆倀able騫朵笉浼氫簡鐞嗕細浣犺瀹氱殑margin錛屽鏋滄兂鏀瑰彉瀹冪殑magin榪樻槸闇瑕佸幓鏀瑰彉瀹冪殑瀹藉害錛坰etWidth錛夈?br />
2 pdf琛ㄥ崟

浣跨敤PdfStamper鏄彲浠ュ~鍏卲df琛ㄥ崟鐨勶紝榪欐牱灝辯粰鍑轟簡涓縐嶅緢濂界殑鎶ヨ〃鐢熸垚鎬濊礬銆?br />word鍒朵綔鎶ヨ〃鏍峰紡-->acrobat杞琾df-->itext濉厖鏁版嵁-->杈撳嚭pdf
榪欏仛闈炲父綆鍗曪紝鍥犱負鍙互姣旇緝瀹規槗鐨勬帶鍒秔df鐨勬牱寮忋傛垜瀵逛簬Java鐨勬姤琛ㄥ伐鍏蜂簡瑙g殑騫朵笉澶氾紝涓嶈繃鍦╦asperreports錛屽嵆浣跨敤GUI宸ュ叿鍋氫竴涓牱寮忔瘮杈冨鏉傜殑鎶ヨ〃涔熶笉鏄庝箞瀹規槗銆傛瘮濡傛湁閭g鏂滅嚎鐨勮〃澶達紝姣旇緝鑺卞摠鐨勫祵濂楄〃鏍箋傝繖鏍風殑鎯呭喌榪樻槸姣旇緝澶氳鐨勶紝瀹㈡埛涓嶄細鍏崇郴浣犲疄鐜拌搗鏉ユ槸鍚﹀洶闅俱備笉榪囨兂瑕佷嬌鐢ㄨ繖縐嶆柟寮忎篃鏈変笉瓚崇殑鍦版柟銆傞鍏堟槸acrobat鎶妛ord杞寲鎴恜df鐨勬椂鍊欙紝鏍煎紡鎬繪槸淇濇寔涓嶅ソ錛岀壒鍒殑鏄瓧浣撱傜劧鍚庢槸鏂囦歡鐨勪綋縐繖鏍風敓鎴愮殑pdf浼氭瘮鐩存帴鐢╥Text鐢熸垚鐨刾df鏂囦歡澶у緢澶氾紝acrobat鍦╬df閲屽姞鍏ヤ簡澶鏃犵敤鐨勪俊鎭傚垵嬈′嬌鐢╥Text濉厖Adobe Designer鐢熸垚鐨刾df琛ㄥ崟鏃朵細鏈夌偣灝忛夯鐑︺傚湪Designer涓璁′簡涓涓猲ame鐨則ext鏂囨湰妗嗙殑緇戝畾鍚嶄負name銆傜収鐫iText涓緥瀛愪嬌鐢ㄤ嬌鐢≒dfStamper鐨剆etField鏂規硶鍘昏繖鏍峰啓form.setField("name", "XXXX");騫朵笉浼氭垚鍔熴傚師鍥犳槸Adobe Designer鐢熸垚鐨勮〃鍗曞悕閮芥槸鍏鋒湁灞傛鐨勶紝瀹冨彲鑳芥槸榪欎釜鏍峰瓙form1[0].#subform[0].name[0]銆備笉榪囨垜浠彲浠ョ敤涓涓柟娉曟妸瀹冧滑鍒楀嚭鏉ワ紝鍙鍋氫竴嬈″氨鐭ラ亾緇撴瀯浜嗭紝鍙互浣跨敤綾諱技涓嬮潰鐨勪唬鐮侊細
PdfReader reader = new PdfReader("form.pdf");
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("registered_flat.pdf"));
AcroFields form = stamp.getAcroFields();
for (Iterator it = form.getFields().keySet().iterator(); it
.hasNext();) {
System.out.println(it.next());
}
濡傛灉鐩存帴鐢╥Text緙栫▼鐢熸垚鐨勮〃鍗曞氨涓嶄細鏈夎繖鏍風殑闂錛岃瀹氱殑浠涔堝悕瀛楀氨鏄粈涔堝悕瀛椼?br />
3 琛ㄥ崟鍏冪礌

pdf騫朵笉鍍廻tml閭f牱鍏鋒湁鑹ソ娓呮櫚鐨勭粨鏋勶紝鑰屾槸涓涓湁灞傛鐨勬枃妗g被鍨嬨傚湪瀹冪殑maillist閲岋紝浣滆呰鏄庝簡iText铏界劧鍙互鎿嶄綔鐜板瓨鐨刾df鏂囦歡浣嗘槸娌″姙娉曞幓榪樺師瀹冪殑緇撴瀯鐨勩傛病鍔炴硶鍍廻tml涓鏍鳳紝鑳戒粠涓涓猵df鏂囦歡鑾峰緱涓涓竻鏅扮殑鈥滄簮鏂囦歡鈥濈殑銆傚叧浜庡眰嬈★紝鍙互浠巌Text涓婂緱鍒拌緇嗙殑璁茶堪錛岃幏鍙栧幓鐪嬬湅pdf瑙勮寖銆傝〃鍗曞拰鏅氭枃鏈槸涓嶅湪涓涓眰涓婄殑銆傛病鍔炴硶閫傜敤瀵瑰緟鏂囨湰琛ㄥ悇涓鏍鋒妸瀹冧滑綆鍗曠殑add榪汥ocument瀵硅薄銆傝幏鍙栦竴涓猚b鐩存帴鍘葷敤緇濆瀹氫綅鐨勬柟娉曞彲浠ュ姞鍏ヨ〃鍗曞厓绱狅紝涓嶈繃寰堝鐨勬椂鍊欏洜涓烘帓鐗堝茍涓嶈兘閭d箞綆鍗曠殑鍘誨仛銆傚氨鏄湪html涓竷灞涓鏍峰彲浠ヤ嬌鐢ㄨ〃鏍煎畾浣嶃傛兂鎶婁竴涓〃鍗曞厓绱犲姞鍏ell錛岃鍊熷姪cell鐨剆etCellEvent鏂規硶銆備互涓涓猚heckbox涓轟緥銆傛柊寤轟竴涓被CheckBoxForm錛屽疄鐜癙dfPCellEvent鎺ュ彛銆傞渶瑕佸疄鐜頒竴涓猚ellLayout鐨勬柟娉曘?br />聽 public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
position鍙互濂藉ソ鍒╃敤錛屽畠鍖呭惈褰撳墠cell鐨勪綅緗俊鎭紝浣犲彲浠ョ敤瀹冩潵紜畾鑷繁checkbox鐨勪綅緗?br />position.top()-position.bottom()灝辮兘寰楀埌楂榩osition.right()-position.left()鍙互寰楀埌闀匡紝濡傛灉闇瑕佽繖涓や釜鍊煎緱鑺卞彲浠ュ姝よ綆椼備笅闈㈢殑浠g爜灝辨槸瀹氫箟涓涓搴︿負a鐨刢heckbox鐨剅ectangle 銆傚畠鍦╟ell涓按騫沖眳涓紝鍨傜洿涔熷眳涓?br />聽 聽 float bo = (position.top()-position.bottom()-a)/2;
聽 聽 float ao = (position.right()-position.left()-a)/2; 聽 聽
聽 聽 Rectangle rectangle = new Rectangle(position.left() + ao, position
聽 聽 聽 聽 聽 .bottom() + bo, position.left() +ao+ a, position.bottom()+ bo + a);
鐒跺悗鎶婂畠鍔犲叆Document
聽 聽 RadioCheckField tf = new RadioCheckField(writer, rectangle, fieldname,
聽 聽 聽 聽 聽 "f");
聽 聽 tf.setCheckType(RadioCheckField.TYPE_SQUARE);
聽 聽 tf.setBorderWidth(1);
聽 聽 tf.setBorderColor(Color.black);
聽 聽 tf.setBackgroundColor(Color.white); 聽 聽 聽
聽 聽 try {
聽 聽 聽 聽 PdfFormField field = tf.getCheckField(); 聽 聽 聽 聽
聽 聽 聽 聽 writer.addAnnotation(field);
聽 聽 } catch (IOException e) {
聽 聽 聽 聽 e.printStackTrace();
聽 聽 } catch (DocumentException e) {
聽 聽 聽 聽 e.printStackTrace();
聽 聽 }
鍏跺畠鐨勫厓绱犱笌姝ょ被浼箋?br />
4 PdfPTable鍜孴able

璇翠笉涓婂摢縐嶆洿濂界敤錛屾湁鏃跺欎笉鑳戒笉浣跨敤PdfPTable銆傚彲鎯滃畠鍙湁setColspan鏂規硶錛屾病鏈塻etRowspan銆傚祵濂楃殑鏃跺欎篃鏈夊尯鍒紝PdfPTable鏄敤addcell錛堬級鍔犲叆宓屽琛ㄧ殑錛宼able鍒欐湁涓涓洿鏄庝簡鐨勬柟娉昳nsertTable錛堬級銆侾dfPTable鎯寵繘琛岃緗産order涔嬬被鐨勬搷浣滆鍏堣幏寰椾竴涓粯璁ell錛?br />pdfPTableName.getDefaultCell().setBorder(Rectangle.NO_BORDER);//璁劇疆鏃犳鐨勮〃
鍙﹀鍦≒dfPTable涓紝涓浜涗慨楗板睘鎬т細鍥犱負璁劇疆鐨勬椂鏈轟笉姝g‘鑰屾病鏈夋晥鏋溿傚錛岄傜敤cell鐨勬瀯閫犲嚱鏁板姞鍏ヤ簡鏂囨湰錛屽湪cell鐨剆etVerticalAlignment錛堬級fangfa鍘昏瀹氬瀭鐩村榻愭柟寮忓氨涓嶄細鏈夋晥銆傝繕鏈変竴涓湁鎰忔濈殑涓嶅悓鏄痶able榛樿澶栬竟妗嗘槸鍔犵矖鐨勶紝鑰孭dfPTable鍒欎竴鏍風矖緇嗐?br />
5 瀛椾綋

iText鐨勪緥瀛愭湁寰堝瓚沖鐢紝緇欏嚭涓浜沺df鐨勫瓧浣撳悕縐板拰緙栫爜錛屽鏋滄兂浣跨敤鍐呭祵瀛椾綋鐨勮瘽銆?br />璇█ PDF 瀛椾綋鍚?
綆浣撲腑鏂?STSong-Light
綣佷綋涓枃 MHei-Medium
MSung-Light
鏃ヨ HeiseiKakuGo-W5
HeiseiMin-W3
闊╄ HYGoThic-Medium
HYSMyeongJo-Medium

瀛楃闆?緙栫爜
綆浣撲腑鏂?UniGB-UCS2-H
UniGB-UCS2-V
綣佷綋涓枃 UniCNS-UCS2-H
UniCNS-UCS2-V
鏃ヨ UniJIS-UCS2-H
UniJIS-UCS2-V
UniJIS-UCS2-HW-H
UniJIS-UCS2-HW-V
闊╄ UniKS-UCS2-H
UniKS-UCS2-H
蹇呴』瑕佹湁Asian鐨勫寘鎵嶅彲浠ョ敤錛屼篃鍙互浣跨敤TrueType瀛椾綋銆?br />


]]>
浣跨敤poi瀵兼垚excel鐨勪竴涓被鍨嬪垽鏂嚱鏁?/title><link>http://m.tkk7.com/pdw2009/archive/2006/12/21/89303.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Thu, 21 Dec 2006 08:10:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2006/12/21/89303.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/89303.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2006/12/21/89303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/89303.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/89303.html</trackback:ping><description><![CDATA[ <p>/**<br />聽 * 鑾峰彇cell涓殑鏁版嵁<br />聽 * @param cell<br />聽 * @return<br />聽 */<br />聽private String readCell(HSSFCell cell) {<br />聽聽if (null == cell) {<br />聽聽聽return "";<br />聽聽}<br />聽聽SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);<br />聽聽switch (cell.getCellType()) {<br />聽聽聽case HSSFCell.CELL_TYPE_STRING: {<br />聽聽聽聽return Strings.trim(cell.getStringCellValue());<br />聽聽聽}<br />聽聽聽case HSSFCell.CELL_TYPE_NUMERIC: {<br />聽聽聽聽if(HSSFDateUtil.isCellDateFormatted(cell)){<br />聽聽聽聽聽<br />聽聽聽聽聽return sdf.format(cell.getDateCellValue());<br />聽聽聽聽}else{<br />聽聽聽聽聽return Strings.trim(new BigDecimal(cell.getNumericCellValue())<br />聽聽聽聽聽聽聽.toString());<br />聽聽聽聽}</p> <p>聽聽聽}<br />聽聽聽case HSSFCell.CELL_TYPE_BOOLEAN: {<br />聽聽聽聽return Strings.trim(String.valueOf(cell.getBooleanCellValue()));<br />聽聽聽}<br />聽聽聽case HSSFCell.CELL_TYPE_FORMULA: {<br />聽聽聽聽return Strings.trim(String.valueOf(cell.getCellFormula()));<br />聽聽聽}<br />聽聽聽<br />聽聽聽default: {<br />聽聽聽聽return Strings.trim(cell.getStringCellValue());<br />聽聽聽}<br />聽聽}<br />聽}</p> <img src ="http://m.tkk7.com/pdw2009/aggbug/89303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2006-12-21 16:10 <a href="http://m.tkk7.com/pdw2009/archive/2006/12/21/89303.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>List 鎺掑簭http://m.tkk7.com/pdw2009/archive/2006/12/18/88636.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Mon, 18 Dec 2006 12:58:00 GMThttp://m.tkk7.com/pdw2009/archive/2006/12/18/88636.htmlhttp://m.tkk7.com/pdw2009/comments/88636.htmlhttp://m.tkk7.com/pdw2009/archive/2006/12/18/88636.html#Feedback0http://m.tkk7.com/pdw2009/comments/commentRss/88636.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/88636.htmlclass Mycomparator implements Comparator{

聽聽聽public int compare(Object arg0, Object arg1) {
聽聽聽聽Step obj0=(Step)arg0;
聽聽聽聽Step obj1=(Step)arg1;
聽聽聽聽if(obj0.getId()<obj1.getId()){
聽聽聽聽聽return 0;
聽聽聽聽}else{
聽聽聽聽聽return 1;
聽聽聽聽}
聽聽聽}
聽聽聽
聽聽}
聽聽Comparator comp = new Mycomparator();
聽聽Collections.sort(historyList,comp);



]]>
JDOM鐨勪竴涓緥瀛?/title><link>http://m.tkk7.com/pdw2009/archive/2006/10/13/74905.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Fri, 13 Oct 2006 01:12:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2006/10/13/74905.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/74905.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2006/10/13/74905.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/74905.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/74905.html</trackback:ping><description><![CDATA[聽import org.jdom.*; <br />import org.jdom.output.*; <br />import org.jdom.input.*; <br />import org.jdom.xpath.*; <br /><br />import java.io.FileOutputStream; <br />import java.lang.reflect.Field; <br />import java.lang.reflect.Method; <br />import java.util.*; <br /><br /><br />/** <br />* @author Peter (C)www.ldtec.com <br />* <br />* 澶勭悊xml閰嶇疆鏂囦歡 <br />* <br />*/ <br /><br />public class SearchUtil { <br />private static String tablelistfile="C:/tomcat/webapps/csms/WEB-INF/search/tablelist.xml"; <br /><br />/** <br />* <p>閫氳繃綾誨弽灝勬潵鑾峰緱xml鏂囦歡鐨勪俊鎭?lt;/p> <br />* @param vbean <br />* @param filepath <br />* @param xpath <br />* @return result <br />*/ <br />public static List search(Class vbean,String xpath){ <br />List result=new ArrayList(); <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br />doc=builder.build(tablelistfile); <br />root=doc.getRootElement(); <br />List xlist=XPath.selectNodes(root,xpath); <br />Field[] field=Class.forName(vbean.getName()).getDeclaredFields(); <br />for(int i=0;i<xlist.size();i++){ <br />Element xele=(Element)xlist.get(i); <br />Object myclass=new Object(); <br />myclass=Class.forName(vbean.getName()).newInstance(); <br />for(int k=0;k<field.length;k++){ <br />String vname=field[k].getName(); <br />String method=vname.substring(0,1).toUpperCase()+vname.substring(1,vname.length()); <br />String vmethod="set"+method; <br />Class[] clazz = new Class[1] ; <br />clazz[0] = String.class ; <br />Method met = Class.forName(vbean.getName()).getMethod(vmethod,clazz) ; <br />Object[] obj = new Object[1] ; <br />obj[0] = xele.getAttributeValue(field[k].getName()); <br />Object ret = met.invoke(myclass,obj) ; <br />} <br />result.add(myclass); <br />} <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br /><br />/** <br />* <p>xml鏂囦歡璺緞浠庣晫闈紶榪涙潵..</p> <br />* @param vbean <br />* @param filepath <br />* @param xpath <br />* @return <br />*/ <br />public static List search(Class vbean,String filepath ,String xpath){ <br />List result=new ArrayList(); <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br />doc=builder.build(filepath); <br />root=doc.getRootElement(); <br />List xlist=XPath.selectNodes(root,xpath); <br />Field[] field=Class.forName(vbean.getName()).getDeclaredFields(); <br />for(int i=0;i<xlist.size();i++){ <br />Element xele=(Element)xlist.get(i); <br />Object myclass=new Object(); <br />myclass=Class.forName(vbean.getName()).newInstance(); <br />for(int k=0;k<field.length;k++){ <br />String vname=field[k].getName(); <br />String method=vname.substring(0,1).toUpperCase()+vname.substring(1,vname.length()); <br />String vmethod="set"+method; <br />Class[] clazz = new Class[1] ; <br />clazz[0] = String.class ; <br />Method met = Class.forName(vbean.getName()).getMethod(vmethod,clazz) ; <br />Object[] obj = new Object[1] ; <br />obj[0] = xele.getAttributeValue(field[k].getName()); <br />Object ret = met.invoke(myclass,obj) ; <br />} <br />result.add(myclass); <br />} <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br /><br />/** <br />* <p>xml鏂囦歡璺緞鐢遍〉闈紶榪涙潵</p> <br />* @param vbean <br />* @param filepath <br />* @param xpath <br />* @param map <br />* @return <br />*/ <br />public static boolean modify(Class vbean,String filepath,String xpath,Map map){ <br />boolean result=false; <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br />doc=builder.build(filepath); <br />root=doc.getRootElement(); <br />List xlist=XPath.selectNodes(root,xpath); <br />Element xele=(Element)xlist.get(0); <br />Field[] field=Class.forName(vbean.getName()).getDeclaredFields(); <br />for(int k=0;k<field.length;k++){ <br />xele.setAttribute(field[k].getName(),(String) map.get(field[k].getName())); <br />} <br /><br />Format format = Format.getCompactFormat(); <br />format.setEncoding("gb2312"); <br />format.setIndent(" "); <br />XMLOutputter XMLOut = new XMLOutputter(format); <br />XMLOut.output(doc,new FileOutputStream(filepath)); <br />result=true; <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br /><br /><br />/** <br />* <p>淇敼鏌愪釜鑺傜偣</p> <br />* @param vbean <br />* @param xpath <br />* @return <br />*/ <br />public static boolean modify(Class vbean,String xpath,Map map){ <br />boolean result=false; <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br />doc=builder.build(tablelistfile); <br />root=doc.getRootElement(); <br />List xlist=XPath.selectNodes(root,xpath); <br />Element xele=(Element)xlist.get(0); <br />Field[] field=Class.forName(vbean.getName()).getDeclaredFields(); <br />for(int k=0;k<field.length;k++){ <br />xele.setAttribute(field[k].getName(),(String) map.get(field[k].getName())); <br />} <br /><br />Format format = Format.getCompactFormat(); <br />format.setEncoding("gb2312"); <br />format.setIndent(" "); <br />XMLOutputter XMLOut = new XMLOutputter(format); <br />XMLOut.output(doc,new FileOutputStream(tablelistfile)); <br />result=true; <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br /><br /><br />/** <br />* <p>鏂囦歡璺緞鐢遍〉闈紶杈撹繘鏉?</p> <br />* @param vbean <br />* @param filepath <br />* @param xpath <br />* @param map <br />* @return <br />*/ <br />public static boolean add(Class vbean,String filepath,String xpath,Map map,String strele){ <br />boolean result=false; <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br /><br />doc=builder.build(filepath); <br />root=doc.getRootElement(); <br />Element tablelistEle=(Element)XPath.selectSingleNode(root,xpath); <br />List xlist=tablelistEle.getChildren(); <br />Element xele=new Element(strele); <br />Field[] field=Class.forName(vbean.getName()).getDeclaredFields(); <br />for(int k=0;k<field.length;k++){ <br />xele.setAttribute(field[k].getName(),(String) map.get(field[k].getName())); <br />} <br />xlist.add(xele); <br /><br />Format format = Format.getCompactFormat(); <br />format.setEncoding("gb2312"); <br />format.setIndent(" "); <br />XMLOutputter XMLOut = new XMLOutputter(format); <br />XMLOut.output(doc,new FileOutputStream(filepath)); <br />result=true; <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br />/** <br />* <p>鍦ㄥ綋鍓峹path璺緞澶?娣誨姞涓涓妭鐐?lt;/p> <br />* @param vbean <br />* @param xpath <br />* @param map <br />* @return <br />*/ <br />public static boolean add(Class vbean,String xpath,Map map,String strele){ <br />boolean result=false; <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br /><br />doc=builder.build(tablelistfile); <br />root=doc.getRootElement(); <br />Element tablelistEle=(Element)XPath.selectSingleNode(root,xpath); <br />List xlist=tablelistEle.getChildren(); <br />Element xele=new Element(strele); <br />Field[] field=Class.forName(vbean.getName()).getDeclaredFields(); <br />for(int k=0;k<field.length;k++){ <br />xele.setAttribute(field[k].getName(),(String) map.get(field[k].getName())); <br />} <br />xlist.add(xele); <br /><br />Format format = Format.getCompactFormat(); <br />format.setEncoding("gb2312"); <br />format.setIndent(" "); <br />XMLOutputter XMLOut = new XMLOutputter(format); <br />XMLOut.output(doc,new FileOutputStream(tablelistfile)); <br />result=true; <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br /><br />/** <br />* <p>鏂囦歡璺緞鐢遍〉闈紶榪涙潵</p> <br />* @param vbean <br />* @param filepath <br />* @param xpath <br />* @param map <br />* @return <br />*/ <br />public static boolean remove(Class vbean,String filepath,String xpath,Map map){ <br />boolean result=false; <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br />doc=builder.build(filepath); <br />root=doc.getRootElement(); <br />List templist=XPath.selectNodes(root,xpath); <br />String key=(String)map.get("key"); <br />String value="/(String)map.get(""value"); <br />int row=0; <br />boolean flag=false; <br />for(int i=0;i<templist.size();i++){ <br />Element tempele=(Element)templist.get(i); <br />if(tempele.getAttributeValue(key).equals(value)){ <br />row=i; <br />flag=true; <br />} <br />} <br />if(flag==false){ <br />return false; <br />} <br />int pos=0; <br />pos=xpath.lastIndexOf("/"); <br />String vpath=xpath.substring(0,pos); <br />Element xele=(Element)XPath.selectSingleNode(root,vpath); <br />List xlist=xele.getChildren(); <br />if(flag){ <br />xlist.remove(row); <br />result=true; <br />} <br /><br />Format format = Format.getCompactFormat(); <br />format.setEncoding("gb2312"); <br />format.setIndent(" "); <br />XMLOutputter XMLOut = new XMLOutputter(format); <br />XMLOut.output(doc,new FileOutputStream(filepath)); <br />result=true; <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br />/** <br />* <p>鍒犻櫎鏌愪釜鑺傜偣,map鍙傛暟蹇呴』鏈変竴涓敭鍚嶄負key鍜寁alue</p> <br />* @param vbean <br />* @param xpath <br />* @param map <br />* @return result <br />*/ <br />public static boolean remove(Class vbean,String xpath,Map map){ <br />boolean result=false; <br />SAXBuilder builder=new SAXBuilder(); <br />Document doc=null; <br />Element root=null; <br />try{ <br />doc=builder.build(tablelistfile); <br />root=doc.getRootElement(); <br />List templist=XPath.selectNodes(root,xpath); <br />String key=(String)map.get("key"); <br />String value="/(String)map.get(""value"); <br />int row=0; <br />boolean flag=false; <br />for(int i=0;i<templist.size();i++){ <br />Element tempele=(Element)templist.get(i); <br />if(tempele.getAttributeValue(key).equals(value)){ <br />row=i; <br />flag=true; <br />} <br />} <br />if(flag==false){ <br />return false; <br />} <br />int pos=0; <br />pos=xpath.lastIndexOf("/"); <br />String vpath=xpath.substring(0,pos); <br />Element xele=(Element)XPath.selectSingleNode(root,vpath); <br />List xlist=xele.getChildren(); <br />if(flag){ <br />xlist.remove(row); <br />result=true; <br />} <br /><br />Format format = Format.getCompactFormat(); <br />format.setEncoding("gb2312"); <br />format.setIndent(" "); <br />XMLOutputter XMLOut = new XMLOutputter(format); <br />XMLOut.output(doc,new FileOutputStream(tablelistfile)); <br />result=true; <br />}catch(Exception e){ <br />e.printStackTrace(); <br />} <br />return result; <br />} <br />public static void main(String args[]){ <br /><br />Map kk=new HashMap(); <br />kk.put("f1","xxxx"); <br />kk.put("f2","MMMM"); <br />kk.put("f3","JJJJ"); <br />String v="kkk()"; <br /><br />String temp=(v.substring(0,1)).toUpperCase(); <br />String vv=temp+v.substring(1,v.length()); <br />System.out.println("temp->>"+temp); <br />System.out.println("vv->"+vv); <br />String path="c:/kk/lo.xml"; <br />int start=path.lastIndexOf("/"); <br />int end=path.lastIndexOf("."); <br />String xx=path.substring(start+1,end); <br />System.out.println("----xx->"+xx); <br />} <br /><br />} <img src ="http://m.tkk7.com/pdw2009/aggbug/74905.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2006-10-13 09:12 <a href="http://m.tkk7.com/pdw2009/archive/2006/10/13/74905.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>JDOM鍏ラ棬http://m.tkk7.com/pdw2009/archive/2006/10/13/74904.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Fri, 13 Oct 2006 01:09:00 GMThttp://m.tkk7.com/pdw2009/archive/2006/10/13/74904.htmlhttp://m.tkk7.com/pdw2009/comments/74904.htmlhttp://m.tkk7.com/pdw2009/archive/2006/10/13/74904.html#Feedback0http://m.tkk7.com/pdw2009/comments/commentRss/74904.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/74904.html 1) JDOM鐨勭粍鎴?浠諱綍涓涓鏋墮兘鏈夎嚜宸辯殑緇勬垚緇撴瀯,JDOM铏借涓嶄笂鏄竴涓鏋?鍥犱負濂規病鏈夋彁渚涚粰鎴戜滑浠諱綍鐨勬墿灞曟鏋?濡傛灉璇村叾鏄竴涓伐鍏?閭d箞濂規槸涓涓粨鏋勯潪甯哥畝鍗曠殑XML鎿嶄綔宸ュ叿,鍏跺寘鎻掑涓嬪寘:

org.JDOM
org.JDOM.input
org.JDOM.output
org.JDOM.adapters
org.JDOM.transform
鎴戜滑鍙互浠庡瓧闈笂鍘葷悊瑙f瘡涓寘鐨勪綔鐢? JDOM鍖呭惈浠ヤ笅綾誨瀷
Attribute
CDATA
Coment
DocType
Document
Element
EntityRef
Namespace
ProscessingInstruction
Text
鍦ㄥ紑鍙慾dom搴旂敤紼嬪簭涓垜浠墍鐢ㄧ殑鎵鏈夌被鍨?...灝辮繖鍑犱釜綾誨瀷寰堢畝鍗曞氨鍙悊瑙?涓嬮潰浠嬪涓涓瘡涓紑鍙戝寘鐨勪綔鐢?
*銆org.JDOM.transform
鍦ㄦ秹鍙妜slt鏍煎紡杞崲鏃跺簲浣跨敤涓嬮潰鐨?涓被
JDOMSource
JDOMResult

錛娿org.JDOM.input
杈撳叆綾伙紝涓鑸敤浜庢枃妗g殑鍒涘緩宸ヤ綔
SAXBuilder
DOMBuilder
ResultSetBuilder
娉╦dom鐨勮緭鍏ユ簮闈炲父騫挎硾,鍙互鏄瓧絎︿覆,鍙互鏄叾瀹冪殑XML宸ュ叿鐢熸垚鐨刋ML鏂囦歡銆?
* org.JDOM.output
杈撳嚭綾伙紝鐢ㄤ簬鏂囨。杞崲杈撳嚭
XMLOutputter
SAXOutputter
DomOutputter
JTreeOutputter
浠庝互涓婅緭鍑虹被鍙互鐪嬪嚭jdom鍙互杈撳嚭甯哥敤綾誨瀷鍙稾ML鏂囦歡
涓嬮潰鏄垜鍐欑殑涓涓xml錛屼竴涓垱寤篨ML鐨勪袱涓緥紼?
==================
package jdom;

/**
* @author 
* TODO 瀛︿範鐢ㄤ緥 ,pdw2009@tom.com
*
*/
import org.jdom.*;
import org.jdom.input.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.*;
import java.util.*;
public class readabc {

public static void main(String[] args) throws Exception{
SAXBuilder sb=new SAXBuilder();//寤虹珛鏋勯犲櫒
Document doc=sb.build(new FileInputStream("E:\\eclipse\\myworkspace\\base\\src\\jdom\\abc.xml"));
Element root=doc.getRootElement(); //鑾峰緱鏍圭粨鐐?

List list=root.getChildren(); //灝嗘墍鏈夋牴緇撶偣涓嬬殑瀛愮粨鐐規斁鍏ist
for(int i=0;i<list.size();i++){
System.out.println("----------------------");
Element item=(Element)list.get(i); //鑾峰緱瀹炰綋緇撲綋

//鐢ㄤ簬鑾峰緱灞炴?
String name=item.getAttributeValue("id");
System.out.println("Name---->"+name);
//鑾峰緱浜嗚妭鐐?

String temptitle=item.getChildText("title");
System.out.println("嫻嬭瘯"+temptitle); //浣跨敤item鑾峰緱瀛愯妭鐐瑰睘鎬?

Element sub=item.getChild("title");
String title=sub.getText();
System.out.println("title---->"+title);

Element sub2=item.getChild("email");
String email=sub2.getText();
System.out.println("email-->"+email);

Element sub3=item.getChild("content");
String content=sub3.getValue();
System.out.println("content-->"+content);

}

}
}
-----------浠ヤ笂浠g爜瑕佽鐨剎ml鏂囦歡鍐呭濡備笅----------------------------
<?xml version="1.0" encoding="gb2312"?>
<messages>
<message id="jhgjg">i <title>jhgjg</title>
<content>jhgjg</content>
<email>jhjh</email>
</message>
<message id="fdsa">
<title>fdsa</title>
<content>fasdf</content>
<email>fsadfa</email>
</message>
</messages>
--------------------------------------------------------------------------------------------
鍒涘緩涓涓獂ml鏂囦歡
----------------
/*
* Created on 2000-1-1
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package jdom;
import java.io.FileWriter;

import org.jdom.*;
import org.jdom.adapters.*;
import org.jdom.adapters.*;
import org.jdom.input.*;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import java.io.*;
/**
* @author *
* TODO 瀛︿範鐢ㄤ緥 ,pdw2009@tom.com
*
*/
public class createonexml {

public static void main(String[] args)throws Exception {
Element carElement=new Element("car");
Document mydoc=new Document(carElement);
//carElement.addAttribute(new Attribute("vin", "123fhg5869705iop90"));

//娣誨姞鍐呭
carElement.addContent(new Element("make").addContent("DF"));
carElement.addContent(new Element("year").addContent("1997"));
carElement.addContent(new Element("color").addContent("green"));
carElement.addContent(new Element("listenr").addContent("SSDDDBBA"));
//娣誨姞娉ㄨВ
carElement.addContent(new Comment("鎻忚堪涓杈嗚濺"));

//杈撳嚭鍒版枃浠?
XMLOutputter outer=new XMLOutputter();
FileWriter fw=new FileWriter("E:\\eclipse\\myworkspace\\base\\src\\jdom\\car.xml");
Format fm=Format.getPrettyFormat(); //璁懼畾XML鏂囦歡鐨勮緭鍑烘牸寮?
fm.setEncoding("GBK");

outer.setFormat(fm);
outer.output(mydoc,fw);
outer.output(mydoc,System.out);
fw.close();
}
}
------------------浠ヤ笂浠g爜鐢熸垚鐨剎ml鏂囦歡鍐呭濡備笅---------------
<?xml version="1.0" encoding="GBK"?>
<car>
<make>DF</make>
<year>1997</year>
<color>green</color>
<listenr>SSDDDBBA</listenr>
<!--鎻忚堪涓杈嗚濺-->
</car>
---------------------------------------------------------------------------------------
鍦╦dom 1銆?鐗堟湰閲岃緭鍑簒ml鏂囨。鏃訛紝鎴戜滑蹇呴』瀹氫箟璇ユ枃妗g殑鏍煎紡錛屽xml鏂囦歡鐨勭紪杈戞牸寮忥紝杈撳嚭鐨剎ml鏂囨。鏄惁鎹㈣錛屾槸鍚﹀垹闄ゆ垜浣滅殑絀烘牸錛岀瓑銆傛墍浠ュ湪杈撳嚭xml鏂囨。鏃墮渶瀹氫箟涓涓狥ormat瀵硅薄綾?騫剁粰鐩稿叧灞炴ц祴鍊鹼紝鐒跺悗璁懼畾XMLOutputter鎵鐢ㄥ埌鐨勬牸寮忕被,outter.setFormat()銆?
璇峰叧娉ㄦ垜鏈夊叧JDOM鐨勬枃绔犲笇鏈涘浣犳湁鎵甯姪銆傘傘傘傘?

璇︾粏璇存槑璇峰弬鑰僯dom API鏂囨。 1 lonely wolf   1 灝嗕竴涓獂ml鏂囦歡杈撳嚭鍒頒竴涓瓧絎︿覆瀵硅薄閲?
XMLOutputter outputter = new XMLOutputter();
Element element = new Element("Greeting");
String hello = outputter.outputString(element);

2 涓涓猯ist杞崲鎴愪竴涓獂ml鏂囦歡銆傘傝櫧鐒跺叾list涓殑瀛楁鏄浐瀹氫簡錛屾垜浠篃鍙互淇敼綾婚泦杞崲浠g爜錛屼互瀹炵幇鍔ㄦ佸瓧孌電殑杞崲

package jdom;
import java.io.FileWriter;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

/**
* @author  pdw2009@tom.com
* TODO 灝嗕竴涓狶ist瀵硅薄,杞崲涓涓猉ML鏂囦歡
*/
class Person{
private String ID; //瀛﹀彿
private String name; //濮撳悕
private String addr; //鍦板潃
private String tel; //鑱旂郴鐢佃瘽
private String email; //email鍦板潃
/**
* @return Returns the addr.
*/
public String getAddr() {
return addr;
}
/**
* @param addr The addr to set.
*/
public void setAddr(String addr) {
this.addr = addr;
}
/**
* @return Returns the iD.
*/
public String getID() {
return ID;
}
/**
* @param id The iD to set.
*/
public void setID(String id) {
ID = id;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return Returns the tel.
*/
public String getTel() {
return tel;
}
/**
* @param tel The tel to set.
*/
public void setTel(String tel) {
this.tel = tel;
}
/**
* @return Returns the email.
*/
public String getEmail() {
return email;
}
/**
* @param email The email to set.
*/
public void setEmail(String email) {
this.email = email;
}
}

public class listtoxml {
public List creatlist(){
List list=new ArrayList();
Person person=new Person();
person.setAddr("騫胯タ鍚堟鄲");
person.setID("1048");
person.setName("hfggf");
person.setTel("138777778888");
person.setEmail("pdw2009@tom.com");
list.add(person);

person.setAddr("騫胯タ鍗楀畞");
person.setID("1036");
person.setName("锠㈠崲");
person.setTel("1387778888");
person.setEmail("XXXXX@tom.com");
list.add(person);
return list;
}
public static void main(String[] args) throws Exception {
listtoxml lx=new listtoxml();
List list=lx.creatlist(); //鐢熸垚Person綾葷殑瀵硅薄list
Element root=new Element("Student");//鏍規潯鐩?
Iterator it=list.iterator(); //鑾峰彇iterator鎺ュ彛
while(it.hasNext()){
Person p=(Person)it.next();
Element person=new Element("Person");
person.setAttribute("ID",p.getID());
root.addContent(person); //鍦ㄦ牴鍏冪礌涓?娣誨姞涓涓猵erson瀛愬厓绱?

Element ele=new Element("Name");
ele.setText(p.getName());
person.addContent(ele); //鍦╬erson鍏冪礌涓嬫坊鍔犱竴涓猲ame鐨勫瓙鍏冪礌

Element addr=new Element("Address");
addr.setText(p.getAddr());
person.addContent(addr);

Element tel=new Element("tel");
tel.setText(p.getTel());
person.addContent(tel);

Element email=new Element("email");
email.setText(p.getEmail());
person.addContent(email);

}
Document doc=new Document(root);
XMLOutputter outer=new XMLOutputter();
Format fm=Format.getPrettyFormat();
fm.setEncoding("GBK");
outer.setFormat(fm);
FileWriter fw=new FileWriter("E:\\eclipse\\myworkspace\\base\\src\\jdom\\listtoxml.xml");
outer.output(doc,fw); //鍙渶瑕佹妸鑷繁瀹氫箟鐨凢ileWriter鏇挎崲鎺塖ystem.out灝卞彲浠ョ‘瀹歺ml鏂囦歡鐨勮緭鍑轟簡
}
}

浠呬緵鍙備笌錛屽彧闇瑕佹坊鍔犱綘鐨刯dbc榪炴帴渚夸簬宸ヤ綔鍙疄鐜幫紝浠庢暟鎹簱閲屽彇鍑鴻褰曞茍鐢?/td>


瀹氫綅鑺傜偣
XML
鏄爲鐘剁粨鏋勶紝綾諱技妗f緋葷粺鍐呮暟鎹す鐨勭粨鏋勶紝XPath涔熺被浼兼。妗堢郴緇熺殑璺緞鍛藉悕鏂瑰紡銆備笉榪?/span>XPath 鏄竴縐嶆ā寮?/span>(Pattern)錛屽彲浠ラ夊嚭 XML妗f涓紝璺緞絎﹀悎鏌愪釜妯″紡鐨勬墍鏈夎妭鐐瑰嚭鏉ャ備緥濡傝閫?/span>catalog搴曚笅鐨?/span>cd涓墍鏈?/span>price鍏冪礌鍙互鐢細
/catalog/cd/price    


濡傛灉XPath鐨勫紑澶存槸涓涓枩綰匡紙/錛変唬琛ㄨ繖鏄粷瀵硅礬寰勩傚鏋滃紑澶存槸涓や釜鏂滅嚎錛?/span>//錛夎〃紺烘枃浠朵腑鎵鏈夌鍚堟ā寮忕殑鍏冪礌閮戒細琚夊嚭鏉ワ紝鍗充嬌鏄浜庢爲涓笉鍚岀殑灞傜駭涔熶細琚夊嚭鏉ャ備互涓嬬殑璇硶浼氶夊嚭鏂囦歡涓墍鏈夊彨鍋?/span>cd鐨勫厓绱狅紙鍦ㄦ爲涓殑浠諱綍灞傜駭閮戒細琚夊嚭鏉ワ級錛?/span>


//cd

閫夋嫨鏈煡鐨勫厓绱?/span>
浣跨敤鏄熷彿錛?/span>Wildcards,錛婏級鍙互閫夋嫨鏈煡鐨勫厓绱犮備笅闈㈣繖涓娉曚細閫夊嚭/catalog/cd 鐨勬墍鏈夊瓙鍏冪礌錛?/span>


/catalog/cd/*

浠ヤ笅鐨勮娉曚細閫夊嚭鎵鏈?/span>catalog鐨勫瓙鍏冪礌涓紝鍖呭惈鏈?/span>price浣滀負瀛愬厓绱犵殑鍏冪礌銆?/span>


/catalog/*/price

浠ヤ笅鐨勮娉曚細閫夊嚭鏈変袱灞傜埗鑺傜偣錛屽彨鍋?/span>price鐨勬墍鏈夊厓绱犮?/span>


/*/*/price

浠ヤ笅鐨勮娉曚細閫夋嫨鍑烘枃浠朵腑鐨勬墍鏈夊厓绱犮?/span>


//*
瑕佹敞鎰忕殑鏄紝鎯寵瀛樺彇涓嶅垎灞傜駭鐨勫厓绱狅紝XPath璇硶蹇呴』浠ヤ袱涓枩綰垮紑澶?/span>(//)錛屾兂瑕佸瓨鍙栨湭鐭ュ厓绱犳墠鐢ㄦ槦鍙?/span>(*)錛屾槦鍙峰彧鑳戒唬琛ㄦ湭鐭ュ悕縐扮殑鍏冪礌錛屼笉鑳戒唬琛ㄦ湭鐭ュ眰綰х殑鍏冪礌銆?/span>

閫夋嫨鍒嗘敮
浣跨敤涓嫭鍙峰彲浠ラ夋嫨鍒嗘敮銆備互涓嬬殑璇硶浠?/span>catalog鐨勫瓙鍏冪礌涓彇鍑虹涓涓彨鍋?/span>cd鐨勫厓绱犮?/span>XPath鐨勫畾涔変腑娌℃湁絎?/span>0鍏冪礌榪欑涓滆タ銆?/span>


/catalog/cd[1]

浠ヤ笅璇硶閫夋嫨catalog涓殑鏈鍚庝竴涓?/span>cd鍏冪礌錛氾紙XPathj騫舵病鏈夊畾涔?/span> first() 榪欑鍑藉紡鍠旓紝鐢ㄤ笂渚嬬殑 [1]灝卞彲浠ュ彇鍑虹涓涓厓绱犮?/span>


/catalog/cd[last()]

浠ヤ笅璇硶閫夊嚭鍚湁price瀛愬厓绱犵殑鎵鏈?/span>/catalog/cd鍏冪礌銆?/span>


/catalog/cd[price]

浠ヤ笅璇硶閫夊嚭price鍏冪礌鐨勫肩瓑浜?/span>10.90鐨勬墍鏈?/span>/catalog/cd鍏冪礌


/catalog/cd[price=10.90]

浠ヤ笅璇硶閫夊嚭price鍏冪礌鐨勫肩瓑浜?/span>10.90鐨勬墍鏈?/span>/catalog/cd鍏冪礌 鐨?/span>price鍏冪礌


/catalog/cd[price=10.90]/price

閫夋嫨涓涓互涓婄殑璺緞
浣跨敤Or鎿嶄綔鏁?/span>(|)灝卞彲浠ラ夋嫨涓涓互涓婄殑璺緞銆備緥濡傦細


/catalog/cd/title | catalog/cd/artist
 閫夋嫨鎵鏈?/span>title浠ュ強artist鍏冪礌
 //title | //artist
 

閫夋嫨鎵鏈?/span>title浠ュ強artist浠ュ強price鍏冪礌


//title | //artist | //price
 閫夋嫨灞炴?/span> 
鍦?/span>XPath涓紝闄や簡閫夋嫨鍏冪礌浠ュ錛屼篃鍙互閫夋嫨灞炴с傚睘鎬ч兘鏄互@寮澶淬備緥濡傞夋嫨鏂囦歡涓墍鏈夊彨鍋?/span>country鐨勫睘鎬э細
 //@country
         

閫夋嫨鎵鏈夊惈鏈?/span>country榪欎釜灞炴х殑cd鍏冪礌錛?/span>

 
//cd[@country]
         

浠ヤ笅璇硶閫夋嫨鍑哄惈鏈夊睘鎬х殑鎵鏈?/span>cd鍏冪礌

 
//cd[@*]
         

浠ヤ笅璇硶閫夋嫨鍑?/span>country灞炴у間負UK鐨?/span>cd鍏冪礌

 
//cd[@country='UK']


]]>
java杈撳叆涓庤緭鍑?/title><link>http://m.tkk7.com/pdw2009/archive/2006/10/07/73667.html</link><dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator><author>鏈夌尗鐩鎬即鐨勬棩瀛?/author><pubDate>Sat, 07 Oct 2006 12:52:00 GMT</pubDate><guid>http://m.tkk7.com/pdw2009/archive/2006/10/07/73667.html</guid><wfw:comment>http://m.tkk7.com/pdw2009/comments/73667.html</wfw:comment><comments>http://m.tkk7.com/pdw2009/archive/2006/10/07/73667.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/pdw2009/comments/commentRss/73667.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/pdw2009/services/trackbacks/73667.html</trackback:ping><description><![CDATA[     鎽樿: JAVA 涓畾涔変簡涓ょ杈撳叆杈撳嚭嫻侊細瀛楃嫻併佸瓧鑺傛祦銆傚瓧鑺傛祦鐢變袱涓《灞傜殑鎿嶈薄綾伙紝 InputStream 銆? OutputStream 綾繪瀯鎴愶紝姣忎釜鎿嶈薄綾伙紝閮芥湁鍏跺叿浣撳瓙綾匯備笅琛ㄦ槸涓浜涘父鐢ㄧ殑瀛楄妭嫻佺被銆? 聽 ...  <a href='http://m.tkk7.com/pdw2009/archive/2006/10/07/73667.html'>闃呰鍏ㄦ枃</a><img src ="http://m.tkk7.com/pdw2009/aggbug/73667.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/pdw2009/" target="_blank">鏈夌尗鐩鎬即鐨勬棩瀛?/a> 2006-10-07 20:52 <a href="http://m.tkk7.com/pdw2009/archive/2006/10/07/73667.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍏充簬綰跨▼http://m.tkk7.com/pdw2009/archive/2006/10/07/73666.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Sat, 07 Oct 2006 12:48:00 GMThttp://m.tkk7.com/pdw2009/archive/2006/10/07/73666.htmlhttp://m.tkk7.com/pdw2009/comments/73666.htmlhttp://m.tkk7.com/pdw2009/archive/2006/10/07/73666.html#Feedback0http://m.tkk7.com/pdw2009/comments/commentRss/73666.htmlhttp://m.tkk7.com/pdw2009/services/trackbacks/73666.html闃呰鍏ㄦ枃

]]>
主站蜘蛛池模板: 久久久久免费看黄A片APP| MM131亚洲国产美女久久| 污视频网站免费在线观看| 亚洲一区无码精品色| 在线人成精品免费视频| 精品无码专区亚洲| 亚洲bt加勒比一区二区| 精品久久久久久久免费加勒比| 精品久久久久久国产免费了| 亚洲制服在线观看| 中文字幕日韩亚洲| 毛片免费全部免费观看| 久久www免费人成看国产片| 久久精品国产99国产精品亚洲| 亚洲第一永久AV网站久久精品男人的天堂AV| 久久国产乱子免费精品| 亚洲AV噜噜一区二区三区| 亚洲国产一区二区a毛片| 亚洲av手机在线观看| 日本免费一区二区在线观看| 国产V片在线播放免费无码 | 亚洲综合最新无码专区| 久草视频免费在线观看| 久久久精品视频免费观看 | 亚洲AV中文无码字幕色三| 国产婷婷高清在线观看免费| 久久久久久毛片免费播放| 国产免费福利体检区久久| 国产亚洲欧美日韩亚洲中文色| 亚洲国产美女在线观看| 久久久久久久尹人综合网亚洲| 日本免费电影一区| 在线天堂免费观看.WWW| 一级毛片在线免费看| 成人网站免费大全日韩国产| 国产精品成人亚洲| 亚洲女子高潮不断爆白浆| 亚洲人成影院午夜网站| 久久亚洲精品成人无码网站 | 五月婷婷免费视频| 99亚洲精品卡2卡三卡4卡2卡|