??xml version="1.0" encoding="utf-8" standalone="yes"?>成人午夜激情影院,国产精品一区二区无线,国产综合亚洲精品一区二http://www.aygfsteel.com/pdw2009/category/14802.htmlJ2EE相关应用技术日?/description>zh-cnFri, 07 Aug 2009 11:25:50 GMTFri, 07 Aug 2009 11:25:50 GMT60Html Parse 最?jng)_?/title><link>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2008/06/19/209125.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/209125.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2008/06/19/209125.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/209125.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/aggbug/209125.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2008-06-19 11:53 <a href="http://www.aygfsteel.com/pdw2009/archive/2008/06/19/209125.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>加密与编?/title><link>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2008/06/19/209121.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/209121.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2008/06/19/209121.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/209121.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pdw2009/services/trackbacks/209121.html</trackback:ping><description><![CDATA[<p>转移? <a >http://php.11519.net/5jblog/?p=414</a></p> <img src ="http://www.aygfsteel.com/pdw2009/aggbug/209121.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2008-06-19 11:45 <a href="http://www.aygfsteel.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://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2008/06/19/209119.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/209119.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2008/06/19/209119.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/209119.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pdw2009/services/trackbacks/209119.html</trackback:ping><description><![CDATA[     摘要: 把最q工作中所写的代码贴一?以备后用,如能l予你帮助我万分高兴 package com.easylotto.omas.util; import java.util.*; import java.io.*; import org.apache.commons.lang.*; /**  * 替换HTMl里面的字W?n...  <a href='http://www.aygfsteel.com/pdw2009/archive/2008/06/19/209119.html'>阅读全文</a><img src ="http://www.aygfsteel.com/pdw2009/aggbug/209119.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2008-06-19 11:33 <a href="http://www.aygfsteel.com/pdw2009/archive/2008/06/19/209119.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA和JAVAC 命o(h)?http://www.aygfsteel.com/pdw2009/archive/2008/06/12/207413.html有猫怼的日?/dc:creator>有猫怼的日?/author>Thu, 12 Jun 2008 08:00:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2008/06/12/207413.htmlhttp://www.aygfsteel.com/pdw2009/comments/207413.htmlhttp://www.aygfsteel.com/pdw2009/archive/2008/06/12/207413.html#Feedback0http://www.aygfsteel.com/pdw2009/comments/commentRss/207413.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/207413.htmlJAVA和JAVAC 命o(h)?/a>
javac和java命o(h)行中?classpath选项
q是个很基础的问题,但是因ؓ(f)基本上都是用现有的IDE工具 来开发javaE序Q所以很有人意识到q一炏V?br /> javac
-classpathQ设定要搜烦(ch)cȝ路径Q可以是目录Qjar文gQzip文gQ里面都是class文gQ,?x)覆盖掉所有在CLASSPATH里面的设定?br /> -sourcepathQ?讑֮要搜索编译所需java 文g的\径,可以是目录,jar文gQzip文gQ里面都是java文gQ?br /> 所以一个完整的javac命o(h)行应该是q样的,
假设abc.java在\径c:\src里面Q在M的目录的都可以执行以下命令来~译?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

表示~译需要c:\classed下面的class文gQc:\jar\abc.jar里面的class文gQc:\zip\abc.zip里面的class文g
q需要c:\source\project1\src下面的源文gQc:\source\project2 \lib\src.jar里面的源文gQc:\source\project3\lib\src.zip里面的源文gQ?br style="color: rgb(255,0,0)" /> 注意QjarQzip里面的源文g不会(x)有什么改动,目录下的源文Ӟ有可能会(x)被重新编译?br /> java
-classpathQ?讑֮要搜索的cȝ路径Q可以是目录Qjar文gQzip文gQ里面都是class文gQ,?x)覆盖掉所有的CLASSPATH的设定?br /> ׃所要执行的cM是要搜烦(ch)的类的一部分Q所以一定要把这个类的\径也攑ֈ-classpath的设|里面?br /> 表现在,在要执行的类的\径里面执行javaӞ一定要d上点P.Q标C本目录也要搜烦(ch)?br />
假设abc.class在\径c:\src里面
可以在Q何\径下执行以下命o(h)
java -classpath c:\classes;
c:\jar\abc.jar;c:\zip\abc.zip;c:\src abc

问题Q如果main.class属于c:\jar\abc.jarQƈ且在com.cnblogs.jeffchenq个包里Q那么执行java -classpath c:\classes;c:\jar\abc.jar;c:\zip\abc.zip;com.cnblogs.jeffchen.main卛_Q?但是如果classpath中包含多个jar包呢Qƈ且其他jar包中也有com.cnblogs.jeffchen?x)发生什么情况?错误Q?br />
在windows下,
文g路径的分割符为反斜杠  \  
cL者java文g列表的分割符为分?;

在linux?br /> 文g路径的分隔符位斜?/
cL者java文g列表的分隔符为冒?:

一个linux下编译和q行的例?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://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2008/04/15/193046.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/193046.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2008/04/15/193046.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/193046.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pdw2009/services/trackbacks/193046.html</trackback:ping><description><![CDATA[前段旉需要用到这斚w的技?写了(jin)几个例子,不加文字说明,只脓(chung)代码<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;目前q泛使用的算法有MD4、MD5、SHA-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 />      * 单一摘要法Q不使用密码<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 />  * U钥加密Q也U对U性密码,?解密双方׃n同一密钥<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 />      * 加必解密例子<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">获得一个私鈅加密类CipherQECB是加密方式,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">使用U鈅加密</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 />      * 从文件加载密钥和密文q行解密例子(新jdk不懂怎么加蝲)<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 />  *  非对U性加密,也叫公钥加密 产开两个密钥Q私钥,公钥Q私钥加密只有公钥才能解P同时公钥加密只有U钥能解开.<br />  *  目前JDK5提供的RSA法<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 />      * 加密解密例子<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">构成一个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 />         </span><span style="color: #008000">//</span><span style="color: #008000">保存?U密?/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">获得一个RSA的Cipherc,使用公鈅加密</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">使用U鈅解密</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 />      * 加裁U钥Q解密公钥加密的文的文g<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">U钥加蝲</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 />  *   使用RSAU钥对信息摘要签名,然后用公钥进行解?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://www.aygfsteel.com/pdw2009/aggbug/193046.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2008-04-15 11:44 <a href="http://www.aygfsteel.com/pdw2009/archive/2008/04/15/193046.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Unicode ?字符?转换成汉?/title><link>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2008/02/18/180485.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/180485.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2008/02/18/180485.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/180485.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pdw2009/services/trackbacks/180485.html</trackback:ping><description><![CDATA[<p><br /> 例子代码如相,原理我还没弄明白<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://www.aygfsteel.com/pdw2009/aggbug/180485.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2008-02-18 16:18 <a href="http://www.aygfsteel.com/pdw2009/archive/2008/02/18/180485.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java api提供的正则表辑ּhttp://www.aygfsteel.com/pdw2009/archive/2008/01/21/176744.html有猫怼的日?/dc:creator>有猫怼的日?/author>Mon, 21 Jan 2008 05:57:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2008/01/21/176744.htmlhttp://www.aygfsteel.com/pdw2009/comments/176744.htmlhttp://www.aygfsteel.com/pdw2009/archive/2008/01/21/176744.html#Feedback0http://www.aygfsteel.com/pdw2009/comments/commentRss/176744.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/176744.html 在java中正则运主要由三部分构?

1、模式Parttern

2、知配器Matcher

3、输入字W串

参考如下例子和别的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(
"呵呵,正则表达?/span>"));
    }

}

 

q篇介绍java 正则的blog写得不错Q细?j)看一遍就能弄懂个大概
http://blog.csdn.net/ambitiontan/archive/2005/12/21/558195.aspx

最后切记正则的目的Q对字符串正行,查找匚w、替换、删除等工作?/p>

 



]]>
javad资源文ghttp://www.aygfsteel.com/pdw2009/archive/2007/10/11/152182.html有猫怼的日?/dc:creator>有猫怼的日?/author>Thu, 11 Oct 2007 15:54:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2007/10/11/152182.htmlhttp://www.aygfsteel.com/pdw2009/comments/152182.htmlhttp://www.aygfsteel.com/pdw2009/archive/2007/10/11/152182.html#Feedback2http://www.aygfsteel.com/pdw2009/comments/commentRss/152182.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/152182.html如何d资源文gQ?br /> Q一Q?br /> Properties props = new Properties();   
props.load(new FileInputStream("db.properties"));
Q二Q?br /> blog.properties文g如下
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;
  }
}
Q三Q?br />  Properties props=new Properties();
 props.load(BugFactory.class.getResourceAsStream("xx.properties"));
 String name = props.getPropery("xxxx");
 此时xx.properties应该与该cL在同一个目?
Q四Q?br />  ResourceBundle res = ResourceBundle.getBundle("yy.properties");
 String name = res.getString("yyyy");
 yy.properties应放?WEB-INF/classes目录
Q五Q?br /> 如果你这个Bean打包的话Q就把这个文件放在包内?/div>
我一般是q样写的
Properties prop = new Properties();
try
{
 InputStream is = getClass().getResourceAsStream("db.properties");
 prop.load(is);
 if(is!=null)
    is.close();
}
另:(x)
props.load(new FileInputStream("db.properties")); 是读取当前目录的db.properties文g
getClass.getResourceAsStream("db.properties"); 是读取当前类所在位|一L(fng)db.properties文g
getClass.getResourceAsStream("/db.properties"); 是读取ClassPath的根的db.properties文g,注意ClassPath如果是多个\径或者jar文g?只要在Q意一个\径目录下或者jar文g里的根下都可?如果存在于多个\径下的话,按照ClassPath中的先后序,使用先找到的,其余忽略.


]]>javax.mail使用例子http://www.aygfsteel.com/pdw2009/archive/2007/10/08/151180.html有猫怼的日?/dc:creator>有猫怼的日?/author>Mon, 08 Oct 2007 14:40:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2007/10/08/151180.htmlhttp://www.aygfsteel.com/pdw2009/comments/151180.htmlhttp://www.aygfsteel.com/pdw2009/archive/2007/10/08/151180.html#Feedback6http://www.aygfsteel.com/pdw2009/comments/commentRss/151180.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/151180.html阅读全文

]]>
jdk5多线E??http://www.aygfsteel.com/pdw2009/archive/2007/09/05/142835.html有猫怼的日?/dc:creator>有猫怼的日?/author>Wed, 05 Sep 2007 02:51:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2007/09/05/142835.htmlhttp://www.aygfsteel.com/pdw2009/comments/142835.htmlhttp://www.aygfsteel.com/pdw2009/archive/2007/09/05/142835.html#Feedback5http://www.aygfsteel.com/pdw2009/comments/commentRss/142835.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/142835.html  该文转移?nbsp; http://php.11519.net/5jblog/?p=401



]]>
javacd例?/title><link>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2007/08/29/141077.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/141077.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2007/08/29/141077.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/141077.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.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>     * 获得某类的静(rn)态属?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>     * 执行某对象的Ҏ(gu)<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>     * 执行?rn)态类的方?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> 试c?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">q州</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://www.aygfsteel.com/pdw2009/aggbug/141077.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2007-08-29 20:47 <a href="http://www.aygfsteel.com/pdw2009/archive/2007/08/29/141077.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>itextl验ȝ( ?http://www.aygfsteel.com/pdw2009/archive/2007/02/28/101162.html有猫怼的日?/dc:creator>有猫怼的日?/author>Wed, 28 Feb 2007 08:02:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2007/02/28/101162.htmlhttp://www.aygfsteel.com/pdw2009/comments/101162.htmlhttp://www.aygfsteel.com/pdw2009/archive/2007/02/28/101162.html#Feedback0http://www.aygfsteel.com/pdw2009/comments/commentRss/101162.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/101162.html
iText是一个比较底层的pdf库,很多目的pdf操作都是以它为基的。像springQ以?qing)另一个比较有名的报表工具jasperreports。简单的pdf报表输出用它比较合适,比较复杂的话使用h比较困难了(jin)Q你要手工编写太多的代码?br />
比较好的是iText|站上提供相当多的示例代码,比较Ҏ(gu)入门。我q里只说一些在它的文里ƈ没有直接讲到的东ѝ?br />
1 关于Document

Document的几U构造函敎ͼ(x)
public Document();
public Document(Rectangle pageSize);
public Document(Rectangle pageSize,
int marginLeft,
int marginRight,
int marginTop,
int marginBottom);
下面两种比较有用Q如果是你想定义U张大小和边~的时候。对于MarginQiText上提到“You 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). ”不q,对于tablegq不好。tableq不?x)?jin)理会(x)你设定的marginQ如果想改变它的maginq是需要去改变它的宽度QsetWidthQ?br />
2 pdf表单

使用PdfStamper是可以填充pdf表单的,q样qZ(jin)一U很好的报表生成思\?br />word制作报表样式-->acrobat转pdf-->itext填充数据-->输出pdf
q做非常单,因ؓ(f)可以比较Ҏ(gu)的控制pdf的样式。我对于Java的报表工具了(jin)解的q不多,不过在jasperreportsQ即使用GUI工具做一个样式比较复杂的报表也不是怎么Ҏ(gu)。比如有那种斜线的表_(d)比较花哨的嵌套表根{这L(fng)情况q是比较多见的,客户不会(x)关系你实现v来是否困难。不q想要用这U方式也有不的地方。首先是acrobat把word转化成pdf的时候,格式L保持不好Q特别的是字体。然后是文g的体U这L(fng)成的pdf?x)比直接用iText生成的pdf文g大很多,acrobat在pdf里加入了(jin)太多无用的信息。初ơ用iText填充Adobe Designer生成的pdf表单时会(x)有点麻?ch)。在Designer中设计了(jin)一个name的text文本框的l定名ؓ(f)name。照着iText中例子用用PdfStamper的setFieldҎ(gu)去这样写form.setField("name", "XXXX");q不?x)成功。原因是Adobe Designer生成的表单名都是h层次的,它可能是q个样子form1[0].#subform[0].name[0]。不q我们可以用一个方法把它们列出来,只要做一ơ就知道l构?jin),可以使用cM下面的代码:(x)
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());
}
如果直接用iText~程生成的表单就不会(x)有这L(fng)问题Q设定的什么名字就是什么名字?br />
3 表单元素

pdfq不像html那样h良好清晰的结构,而是一个有层次的文类型。在它的maillist里,作者说明了(jin)iText虽然可以操作现存的pdf文g但是没办法去q原它的l构的。没办法像html一P能从一个pdf文g获得一个清晰的“源文g”的。关于层ơ,可以从iText上得到详l的讲述Q获取去看看pdf规范。表单和普通文本是不在一个层上的。没办法适用对待文本表各一h它们单的addqDocument对象。获取一个cb直接ȝl对定位的方法可以加入表单元素,不过很多的时候因为排版ƈ不能那么单的d。就是在html中布局一样可以用表格定位。想把一个表单元素加入cellQ要借助cell的setCellEventҎ(gu)。以一个checkboxZ。新Z个类CheckBoxFormQ实现PdfPCellEvent接口。需要实C个cellLayout的方法?br /> (tng) public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
position可以好好利用Q它包含当前cell的位|信息,你可以用它来定自己checkbox的位|?br />position.top()-position.bottom()p得到高position.right()-position.left()可以得到长,如果需要这两个值得花可以如此计。下面的代码是定义一个宽度ؓ(f)a的checkbox的rectangle 。它在cell中水q_中,垂直也居中?br /> (tng)  (tng) float bo = (position.top()-position.bottom()-a)/2;
 (tng)  (tng) float ao = (position.right()-position.left()-a)/2;  (tng)  (tng)
 (tng)  (tng) Rectangle rectangle = new Rectangle(position.left() + ao, position
 (tng)  (tng)  (tng)  (tng)  (tng) .bottom() + bo, position.left() +ao+ a, position.bottom()+ bo + a);
然后把它加入Document
 (tng)  (tng) RadioCheckField tf = new RadioCheckField(writer, rectangle, fieldname,
 (tng)  (tng)  (tng)  (tng)  (tng) "f");
 (tng)  (tng) tf.setCheckType(RadioCheckField.TYPE_SQUARE);
 (tng)  (tng) tf.setBorderWidth(1);
 (tng)  (tng) tf.setBorderColor(Color.black);
 (tng)  (tng) tf.setBackgroundColor(Color.white);  (tng)  (tng)  (tng)
 (tng)  (tng) try {
 (tng)  (tng)  (tng)  (tng) PdfFormField field = tf.getCheckField();  (tng)  (tng)  (tng)  (tng)
 (tng)  (tng)  (tng)  (tng) writer.addAnnotation(field);
 (tng)  (tng) } catch (IOException e) {
 (tng)  (tng)  (tng)  (tng) e.printStackTrace();
 (tng)  (tng) } catch (DocumentException e) {
 (tng)  (tng)  (tng)  (tng) e.printStackTrace();
 (tng)  (tng) }
其它的元素与此类伹{?br />
4 PdfPTable和Table

说不上哪U更好用Q有时候不能不使用PdfPTable。可惜它只有setColspanҎ(gu)Q没有setRowspan。嵌套的时候也有区别,PdfPTable是用addcellQ)(j)加入嵌套表的Qtable则有一个更明了(jin)的方法insertTableQ)(j)。PdfPTable惌行设|border之类的操作要先获得一个默认cellQ?br />pdfPTableName.getDefaultCell().setBorder(Rectangle.NO_BORDER);//讄无框的表
另外在PdfPTable中,一些修饰属性会(x)因ؓ(f)讄的时Z正确而没有效果。如Q适用cell的构造函数加入了(jin)文本Q在cell的setVerticalAlignmentQ)(j)fangfa去设定垂直对齐方式就不会(x)有效。还有一个有意思的不同是table默认外边框是加粗的,而PdfPTable则一L(fng)l?br />
5 字体

iText的例子有很多_用,l出一些pdf的字体名U和~码Q如果想使用内嵌字体的话?br />语言 PDF 字体?
体中?STSong-Light
J体中文 MHei-Medium
MSung-Light
日语 HeiseiKakuGo-W5
HeiseiMin-W3
韩语 HYGoThic-Medium
HYSMyeongJo-Medium

字符?~码
体中?UniGB-UCS2-H
UniGB-UCS2-V
J体中文 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的包才可以用Q也可以使用TrueType字体?br />


]]>
使用poi导成excel的一个类型判断函?/title><link>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2006/12/21/89303.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/89303.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2006/12/21/89303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/89303.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pdw2009/services/trackbacks/89303.html</trackback:ping><description><![CDATA[ <p>/**<br /> (tng) * 获取cell中的数据<br /> (tng) * @param cell<br /> (tng) * @return<br /> (tng) */<br /> (tng)private String readCell(HSSFCell cell) {<br /> (tng) (tng)if (null == cell) {<br /> (tng) (tng) (tng)return "";<br /> (tng) (tng)}<br /> (tng) (tng)SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);<br /> (tng) (tng)switch (cell.getCellType()) {<br /> (tng) (tng) (tng)case HSSFCell.CELL_TYPE_STRING: {<br /> (tng) (tng) (tng) (tng)return Strings.trim(cell.getStringCellValue());<br /> (tng) (tng) (tng)}<br /> (tng) (tng) (tng)case HSSFCell.CELL_TYPE_NUMERIC: {<br /> (tng) (tng) (tng) (tng)if(HSSFDateUtil.isCellDateFormatted(cell)){<br /> (tng) (tng) (tng) (tng) (tng)<br /> (tng) (tng) (tng) (tng) (tng)return sdf.format(cell.getDateCellValue());<br /> (tng) (tng) (tng) (tng)}else{<br /> (tng) (tng) (tng) (tng) (tng)return Strings.trim(new BigDecimal(cell.getNumericCellValue())<br /> (tng) (tng) (tng) (tng) (tng) (tng) (tng).toString());<br /> (tng) (tng) (tng) (tng)}</p> <p> (tng) (tng) (tng)}<br /> (tng) (tng) (tng)case HSSFCell.CELL_TYPE_BOOLEAN: {<br /> (tng) (tng) (tng) (tng)return Strings.trim(String.valueOf(cell.getBooleanCellValue()));<br /> (tng) (tng) (tng)}<br /> (tng) (tng) (tng)case HSSFCell.CELL_TYPE_FORMULA: {<br /> (tng) (tng) (tng) (tng)return Strings.trim(String.valueOf(cell.getCellFormula()));<br /> (tng) (tng) (tng)}<br /> (tng) (tng) (tng)<br /> (tng) (tng) (tng)default: {<br /> (tng) (tng) (tng) (tng)return Strings.trim(cell.getStringCellValue());<br /> (tng) (tng) (tng)}<br /> (tng) (tng)}<br /> (tng)}</p> <img src ="http://www.aygfsteel.com/pdw2009/aggbug/89303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2006-12-21 16:10 <a href="http://www.aygfsteel.com/pdw2009/archive/2006/12/21/89303.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>List 排序http://www.aygfsteel.com/pdw2009/archive/2006/12/18/88636.html有猫怼的日?/dc:creator>有猫怼的日?/author>Mon, 18 Dec 2006 12:58:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2006/12/18/88636.htmlhttp://www.aygfsteel.com/pdw2009/comments/88636.htmlhttp://www.aygfsteel.com/pdw2009/archive/2006/12/18/88636.html#Feedback0http://www.aygfsteel.com/pdw2009/comments/commentRss/88636.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/88636.htmlclass Mycomparator implements Comparator{

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



]]>
JDOM的一个例?/title><link>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2006/10/13/74905.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/74905.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2006/10/13/74905.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/74905.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pdw2009/services/trackbacks/74905.html</trackback:ping><description><![CDATA[ (tng)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配置文g <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>通过cd来获得xml文g的信?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文g路径从界面传q来..</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文g路径由页面传q来</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>文g路径由页面传输进?</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>在当前xpath路径?d一个节?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>文g路径由页面传q来</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参数必须有一个键名ؓ(f)key和value</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://www.aygfsteel.com/pdw2009/aggbug/74905.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2006-10-13 09:12 <a href="http://www.aygfsteel.com/pdw2009/archive/2006/10/13/74905.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JDOM入门http://www.aygfsteel.com/pdw2009/archive/2006/10/13/74904.html有猫怼的日?/dc:creator>有猫怼的日?/author>Fri, 13 Oct 2006 01:09:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2006/10/13/74904.htmlhttp://www.aygfsteel.com/pdw2009/comments/74904.htmlhttp://www.aygfsteel.com/pdw2009/archive/2006/10/13/74904.html#Feedback0http://www.aygfsteel.com/pdw2009/comments/commentRss/74904.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/74904.html 1) JDOM的组?M一个框枉有自ql成l构,JDOM虽说不上是一个框?因ؓ(f)Ҏ(gu)有提供给我们M的扩展框?如果说其是一个工?那么Ҏ(gu)一个结构非常简单的XML操作工具,其包插如下包:

org.JDOM
org.JDOM.input
org.JDOM.output
org.JDOM.adapters
org.JDOM.transform
我们可以从字面上ȝ解每个包的作? JDOM包含以下cd
Attribute
CDATA
Coment
DocType
Document
Element
EntityRef
Namespace
ProscessingInstruction
Text
在开发jdom应用E序中我们所用的所有类?...p几个cd很简单就可理?下面介始一个每个开发包的作?
* org.JDOM.transform
在涉?qing)xslt格式转换时应使用下面?个类
JDOMSource
JDOMResult

Q org.JDOM.input
输入c,一般用于文档的创徏工作
SAXBuilder
DOMBuilder
ResultSetBuilder
注jdom的输入源非常q泛,可以是字W串,可以是其它的XML工具生成的XML文g?
* org.JDOM.output
输出c,用于文档转换输出
XMLOutputter
SAXOutputter
DomOutputter
JTreeOutputter
从以上输出类可以看出jdom可以输出常用cd号XML文g
下面是我写的一个读xmlQ一个创建XML的两个例E?
==================
package jdom;

/**
* @author 
* TODO 学习(fn)用例 ,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(); //所有根l点下的子结Ҏ(gu)入list
for(int i=0;i<list.size();i++){
System.out.println("----------------------");
Element item=(Element)list.get(i); //获得实体l体

//用于获得属?
String name=item.getAttributeValue("id");
System.out.println("Name---->"+name);
//获得?jin)节?

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);

}

}
}
-----------以上代码要读的xml文g内容如下----------------------------
<?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>
--------------------------------------------------------------------------------------------
创徏一个xml文g
----------------
/*
* 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 学习(fn)用例 ,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"));

//d内容
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"));
//d注解
carElement.addContent(new Comment("描述一辆R"));

//输出到文?
XMLOutputter outer=new XMLOutputter();
FileWriter fw=new FileWriter("E:\\eclipse\\myworkspace\\base\\src\\jdom\\car.xml");
Format fm=Format.getPrettyFormat(); //讑֮XML文g的输出格?
fm.setEncoding("GBK");

outer.setFormat(fm);
outer.output(mydoc,fw);
outer.output(mydoc,System.out);
fw.close();
}
}
------------------以上代码生成的xml文g内容如下---------------
<?xml version="1.0" encoding="GBK"?>
<car>
<make>DF</make>
<year>1997</year>
<color>green</color>
<listenr>SSDDDBBA</listenr>
<!--描述一辆R-->
</car>
---------------------------------------------------------------------------------------
在jdom 1?版本里输出xml文Ӟ我们必须定义该文的格式Q如xml文g的编辑格式,输出的xml文档是否换行Q是否删除我作的I格Q等。所以在输出xml文档旉定义一个Format对象c?q给相关属性赋|然后讑֮XMLOutputter所用到的格式类,outter.setFormat()?
请关注我有关JDOM的文章希望对你有所帮助。。。。?

详细说明请参考jdom API文 1 lonely wolf   1 一个xml文g输出C个字W串对象?
XMLOutputter outputter = new XMLOutputter();
Element element = new Element("Greeting");
String hello = outputter.outputString(element);

2 一个list转换成一个xml文g。。虽然其list中的字段是固定了(jin)Q我们也可以修改c集转换代码Q以实现动态字D늚转换

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 一个List对象,转换一个XML文g
*/
class Person{
private String ID; //学号
private String name; //姓名
private String addr; //地址
private String tel; //联系?sh)?
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("q西合");
person.setID("1048");
person.setName("hfggf");
person.setTel("138777778888");
person.setEmail("pdw2009@tom.com");
list.add(person);

person.setAddr("q西南宁");
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(); //生成Personcȝ对象list
Element root=new Element("Student");//Ҏ(gu)?
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); //在根元素?d一个person子元?

Element ele=new Element("Name");
ele.setText(p.getName());
person.addContent(ele); //在person元素下添加一个name的子元素

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); //只需要把自己定义的FileWriter替换掉System.out可以确定xml文g的输Z(jin)
}
}

仅供参与Q只需要添加你的jdbcq接便于工作可实玎ͼ从数据库里取?gu)录ƈ?/td>


定位节点
XML
是树(wi)状结构,cM档案pȝ内数据夹的结构,XPath也类似案系l的路径命名方式。不q?/span>XPath 是一U模?/span>(Pattern)Q可以选出 XML案中,路径W合某个模式的所有节点出来。例如要?/span>catalog底下?/span>cd中所?/span>price元素可以用:(x)
/catalog/cd/price    


如果XPath的开头是一个斜U(/Q代表这是绝对\径。如果开头是两个斜线Q?/span>//Q表C文件中所有符合模式的元素都会(x)被选出来,即是处于树(wi)中不同的层也会(x)被选出来。以下的语法?x)选出文g中所有叫?/span>cd的元素(在树(wi)中的M层都会(x)被选出来)(j)Q?/span>


//cd

选择未知的元?/span>
使用星号Q?/span>Wildcards,Q)(j)可以选择未知的元素。下面这个语法会(x)选出/catalog/cd 的所有子元素Q?/span>


/catalog/cd/*

以下的语法会(x)选出所?/span>catalog的子元素中,包含?/span>price作ؓ(f)子元素的元素?/span>


/catalog/*/price

以下的语法会(x)选出有两层父节点Q叫?/span>price的所有元素?/span>


/*/*/price

以下的语法会(x)选择出文件中的所有元素?/span>


//*
要注意的是,惌存取不分层的元素,XPath语法必须以两个斜U开?/span>(//)Q想要存取未知元素才用星?/span>(*)Q星号只能代表未知名U的元素Q不能代表未知层U的元素?/span>

选择分支
使用中括号可以选择分支。以下的语法?/span>catalog的子元素中取出第一个叫?/span>cd的元素?/span>XPath的定义中没有W?/span>0元素q种东西?/span>


/catalog/cd[1]

以下语法选择catalog中的最后一?/span>cd元素Q(XPathjq没有定?/span> first() q种函式喔,用上例的 [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>(|)可以选择一个以上的路径。例如:(x)


/catalog/cd/title | catalog/cd/artist
 选择所?/span>title以及(qing)artist元素
 //title | //artist
 

选择所?/span>title以及(qing)artist以及(qing)price元素


//title | //artist | //price
 选择属?/span> 
?/span>XPath中,除了(jin)选择元素以外Q也可以选择属性。属性都是以@开头。例如选择文g中所有叫?/span>country的属性:(x)
 //@country
         

选择所有含?/span>countryq个属性的cd元素Q?/span>

 
//cd[@country]
         

以下语法选择出含有属性的所?/span>cd元素

 
//cd[@*]
         

以下语法选择?/span>country属性gؓ(f)UK?/span>cd元素

 
//cd[@country='UK']


]]>
java输入与输?/title><link>http://www.aygfsteel.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://www.aygfsteel.com/pdw2009/archive/2006/10/07/73667.html</guid><wfw:comment>http://www.aygfsteel.com/pdw2009/comments/73667.html</wfw:comment><comments>http://www.aygfsteel.com/pdw2009/archive/2006/10/07/73667.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pdw2009/comments/commentRss/73667.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pdw2009/services/trackbacks/73667.html</trackback:ping><description><![CDATA[     摘要: JAVA 中定义了(jin)两种输入输出:(x)字符、字节流。字节流׃个顶层的操象c, InputStream ? OutputStream cL成,每个操象c,都有其具体子cR下表是一些常用的字节类?  (tng) ...  <a href='http://www.aygfsteel.com/pdw2009/archive/2006/10/07/73667.html'>阅读全文</a><img src ="http://www.aygfsteel.com/pdw2009/aggbug/73667.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pdw2009/" target="_blank">有猫怼的日?/a> 2006-10-07 20:52 <a href="http://www.aygfsteel.com/pdw2009/archive/2006/10/07/73667.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于U程http://www.aygfsteel.com/pdw2009/archive/2006/10/07/73666.html有猫怼的日?/dc:creator>有猫怼的日?/author>Sat, 07 Oct 2006 12:48:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2006/10/07/73666.htmlhttp://www.aygfsteel.com/pdw2009/comments/73666.htmlhttp://www.aygfsteel.com/pdw2009/archive/2006/10/07/73666.html#Feedback0http://www.aygfsteel.com/pdw2009/comments/commentRss/73666.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/73666.html阅读全文

]]>
վ֩ģ壺 ־| | | ̶| | | | ̷| | ʯ| | | | | | ʹ| ľ| | Ϻӿ| ̨| Ϋ| | ֯| | | ͨ| ׶| | ƽ| | | ƽ| | Ĭ| Ƽ| | ɳ| | ˮ| Ժ| Т|