锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲一本大道无码av天堂,亚洲av无码专区在线,亚洲精品乱码久久久久蜜桃 http://www.tkk7.com/sinpo/鍏蟲敞寮婧愶紝鍙備笌寮婧愶紒zh-cnSun, 11 May 2025 04:39:59 GMTSun, 11 May 2025 04:39:59 GMT60杞歡寮鍙戯紝鎴戜滑榪橀渶瑕佷粈涔?/title><link>http://www.tkk7.com/sinpo/archive/2008/11/17/241049.html</link><dc:creator>寰愯緵娉?/dc:creator><author>寰愯緵娉?/author><pubDate>Mon, 17 Nov 2008 15:09:00 GMT</pubDate><guid>http://www.tkk7.com/sinpo/archive/2008/11/17/241049.html</guid><wfw:comment>http://www.tkk7.com/sinpo/comments/241049.html</wfw:comment><comments>http://www.tkk7.com/sinpo/archive/2008/11/17/241049.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/sinpo/comments/commentRss/241049.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sinpo/services/trackbacks/241049.html</trackback:ping><description><![CDATA[<p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'瀹嬩綋'; "><font face="瀹嬩綋">涓嶆涓嬈℃垜浠殑欏圭洰鍦ㄩ潬寮鍙戜漢鍛樼‖鎵涚潃錛宐ug鏉ヤ笉鍙婁慨鏀癸紝鏂囨。榪樺湪鐚涜ˉ錛岄」鐩粡鐞嗗張鍦ㄥ偓鐫鍑虹増鏈紝姣忎慨鏀逛竴涓猙ug閮借鍦ㄤ唬鐮佺殑娉ユ布涓懜鐖粴鎵撳崐澶╋紝鍗村張鍦ㄥ埗閫犵潃鍙﹀鐨刡ug錛屼負浜嗘枃妗h屽埗閫犵潃鏍規湰娌℃湁鍙傝冧環鍊肩殑鏂囨。銆傛瘡鍙戝竷涓涓増鏈兘瑕佺灮鍓嶉【鍚庡茍涓旀昏鏃犱紤姝㈢殑鍔犵彮錛屼技涔庡紑鍙戜漢鍛樻案榪滄湁騫蹭笉瀹岀殑媧匯?/font></span></p> <p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'瀹嬩綋'; "><font face="瀹嬩綋">鎴戜滑涓嶇闂嚜宸憋紝涓轟粈涔堜細鏈夐偅涔堝澶辮觸鐨勮蔣浠訛紝杞歡寮鍙戞垜浠埌搴曡繕闇瑕佷粈涔堬紵 </font></span></p> <p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'瀹嬩綋'; "><font face="瀹嬩綋">宸ュ叿錛熸垜浠笉涔忎紵澶х殑宸ュ叿錛孖DE鎴戜滑鏈塭clipse銆乮ntelliJ銆乂C++絳夌瓑錛屽緩妯℃垜浠湁Rose銆乼ogether銆乂isio絳夌瓑錛岄厤緗鐞嗘垜浠琒ubversion銆丆VS銆丆learCase絳夌瓑錛宐ug綆$悊鎴戜滑鏈塁learQuest銆乥ugzilla絳夌瓑錛屾枃妗f垜浠瑆ord銆亀ps絳夛紝榪樻湁闆嗘垚銆佹祴璇曠敋鑷崇敓鎴愪唬鐮佺瓑絳夋垜浠兘鏈変紵澶х殑宸ュ叿錛屽伐鍏鋒垜浠笉緙恒傛祦紼嬶紵鐎戝竷妯″瀷銆佽凱浠fā鍨嬨乁P銆乆P鎴戜滑涓嶇己嫻佺▼綆$悊鐨勭悊璁恒傜煡璇嗭紵杞歡寮鍙戠畻鏄竴欏圭煡璇嗗瀷鐨勫伐浣滐紝鎴戜滑鐨勫紑鍙戜漢鍛樹竴鑸兘鏄湰縐戠澹瘯涓氾紝鍐典笖鎼滅儲寮曟搸濡傛鍙戣揪鐨勪粖澶╋紝鐭ヨ瘑鏍規湰涓嶆槸闂錛屽喌涓旀垜浠殑杞歡寮鍙戦渶瑕佸涔堥珮娣辯殑鐭ヨ瘑鍚?</font></span></p> <p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'瀹嬩綋'; "> <font face="瀹嬩綋">浼樼鐨勭悊璁烘敮鎸併佹湁鑳藉姏鐨勪漢鍛樸佸厛榪涚殑宸ュ叿錛岃繖浜涙垜浠兘鍏峰錛屾垜浠墍緙虹殑鍙槸涓縐嶈蔣浠跺紑鍙戠殑鐞嗗康錛岀己灝戣蔣浠跺紑鍙戠殑鎯呭晢銆傛垜浠竴寮濮嬪涔犵紪紼嬬煡璇嗘帴瑙﹀埌鐨勫氨鏄疌璇█鍜屾暟鎹粨鏋勶紝鎱㈡參鐨勪竴浜涚粨鏋勫寲鐨勬濇兂灝辨墡鏍逛簬澶ц剳錛屽叾瀹炲湪鍟嗕笟杞歡涓暟鎹粨鏋勩佺畻娉曞緢灝戞秹鍙婏紝鎴戜滑鎵闇瑕佺殑浠呬粎鏄竴縐嶈璁°佸紑鍙戠殑鐞嗗康銆傛瘮濡傜敤闈㈠悜瀵硅薄鏈潵鏄竴縐嶇畝鍗曠殑鎬濇兂錛岀洰鐨勬槸涓轟簡闄嶄綆杞歡鐨勫鏉傛ц屽嚭鐜扮殑錛屽彲鏄鐔熸倝浜嗙粨鏋勫寲緙栫▼鐨勪漢鍘繪悶鍙嶈岃寰楀緢闅俱備竴浜涘ソ鐨勫疄璺電粡楠屾垜浠篃緇忓父鎻愬埌錛屾瘮濡傛ā鍧楀寲銆佹澗鏁h﹀悎銆侀潰鍚戞帴鍙g紪紼嬨佺被搴斿彧鍏蟲敞鏈亴宸ヤ綔絳夌瓑寮鍙戣璁$悊蹇典互鍙婅鑼冨懡鍚嶃佽灝戒嬌鐢ㄧ殑娉ㄩ噴銆佹竻鏅扮殑緇撴瀯絳変唬鐮佽鑼冧互鍙婃瘡鏃ユ瀯寤恒佹湁鏁堟矡閫氥侀厤緗鐞嗐乥ug綆$悊絳変竴浜涚鐞嗙悊蹇碉紝榪欎簺鍋氳搗鏉ラ兘闈炲父瀹規槗錛屽叧閿槸鎳掓儼鏄漢鐨勬湰鎬э紝涓嶇煡涓嶈涓垜浠氨浼氱姱鐫澶у閮藉湪閲嶅鐨勯敊璇傚鏋滃湪欏圭洰寮宸ヤ箣鍒濆氨鍏呭垎璐交榪欎簺浼樼鐨勭悊蹇碉紝鍦ㄩ」鐩繘琛屼腑鏃犺鏃墮棿澶氱揣閮芥寔涔嬩互鎭掞紝騫朵笖欏圭洰榪涜涓笉鏂殑鍙嶆濅唬鐮佷腑鐨勫潖鍛抽亾錛屼竴緇忓彂鐜扮珛鍗抽噸鏋勶紝鐩鎬俊鎴戜滑鐨勫紑鍙戣繃紼嬩細榪涘叆涓涓壇鎬х殑寰幆涓幓錛屾垜浠殑寮鍙戜漢鍛樺皢浼氫綋浼氬埌浠涔堟槸蹇箰寮鍙戙?/font></span></p> <img src ="http://www.tkk7.com/sinpo/aggbug/241049.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sinpo/" target="_blank">寰愯緵娉?/a> 2008-11-17 23:09 <a href="http://www.tkk7.com/sinpo/archive/2008/11/17/241049.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>璇氬績緇撹瘑鏈夊織浜庣爺絀躲佸紑鍙戝紑婧愯蔣浠剁殑蹇楀悓閬撳悎涔嬪+緇勫緩寮婧愬洟闃?/title><link>http://www.tkk7.com/sinpo/archive/2008/10/31/237895.html</link><dc:creator>寰愯緵娉?/dc:creator><author>寰愯緵娉?/author><pubDate>Fri, 31 Oct 2008 13:00:00 GMT</pubDate><guid>http://www.tkk7.com/sinpo/archive/2008/10/31/237895.html</guid><wfw:comment>http://www.tkk7.com/sinpo/comments/237895.html</wfw:comment><comments>http://www.tkk7.com/sinpo/archive/2008/10/31/237895.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/sinpo/comments/commentRss/237895.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sinpo/services/trackbacks/237895.html</trackback:ping><description><![CDATA[寰愯緵娉紝瑗垮畨錛屼粠浜嬭蔣浠跺紑鍙戣璁″伐浣滐紝鐔熸倝Java璇█錛岀埍濂藉紑鍙戝伐浣滐紝鐗瑰埆鏄痡ava鐩稿叧鐨勭紪紼嬶紝涓氫綑鍏蟲敞寮婧愰」鐩紝璇氬績緇撹瘑蹇楀悓閬撳悎涔嬪+緇勫緩寮婧愬洟闃燂紝鍏卞悓瀛︿範銆佽繘姝ャ佸崗浣溿佷負涓浗寮婧愪簨涓氳礎鐚井钖勪箣鍔涖? <div>寰愯緵娉?sinpo.xu@gmail.com</div> <img src ="http://www.tkk7.com/sinpo/aggbug/237895.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sinpo/" target="_blank">寰愯緵娉?/a> 2008-10-31 21:00 <a href="http://www.tkk7.com/sinpo/archive/2008/10/31/237895.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>JDOM甯哥敤綾諱粙緇嶅強紺轟緥浠g爜http://www.tkk7.com/sinpo/archive/2008/10/25/236589.html寰愯緵娉?/dc:creator>寰愯緵娉?/author>Sat, 25 Oct 2008 13:02:00 GMThttp://www.tkk7.com/sinpo/archive/2008/10/25/236589.htmlhttp://www.tkk7.com/sinpo/comments/236589.htmlhttp://www.tkk7.com/sinpo/archive/2008/10/25/236589.html#Feedback0http://www.tkk7.com/sinpo/comments/commentRss/236589.htmlhttp://www.tkk7.com/sinpo/services/trackbacks/236589.html

JDOM鍥犲叾綆媧佹槗鐢ㄦ槗鎳傜殑API鑰岃騫挎硾鐨勪嬌鐢ㄣ侸DOM甯哥敤鐨勬牳蹇冪被鍙婂畠浠棿鐨勫叧緋誨涓嬪浘鎵紺猴細

Document浠h〃浜嗘枃妗e璞★紝鎶借薄綾籆ontent琛ㄧず鏂囨。涓殑鍐呭鍏冪礌錛屽悇縐嶅唴瀹圭粍鎴愪簡鏂囨。瀵硅薄銆傚父鐢ㄧ殑鍐呭鍏冪礌鏈墄ml鍏冪礌Element銆亁ml娉ㄩ噴Comment銆佹枃鏈琓ext銆備笅闈互濡備笅鐗囨鏉ヨ鏄庡悇綾葷殑鍚箟銆?/font>

<?xml version="1.0" encoding="UTF-8"?>

<customers>

<customer>

<name>寰愯緵娉?lt;/name>

<occupation>developer</occupation>

<!-- comment:following is contact info -->

<contact>

<email>sinpo.xu@hotmail.com</email>

<mobile>15029357227</mobile>

<fix-phone>02985457683</fix-phone>

</contact>

</customer>

</customers>

涓婅堪鏂囨。鐢―ocument鏉ユ娊璞★紱customers涓烘枃妗g殑鏍瑰厓绱狅紙root element 錛夛紝Element鍗充竴涓皝闂搗鏉ョ殑鍏冪礌錛宔lement鍏冪礌鍙互鏈夊瓙鍏冪礌錛屽<mobile>15029357227</mobile>鏄竴涓厓绱狅紝鑰?lt;contact>...</contact>涔熸槸涓涓厓绱狅紝鐢氳嚦<customers>...</customers>涔熸槸涓涓ぇ鍏冪礌錛?lt;!-- ... -->浠h〃浜唜ml涓敞閲婏紝娉ㄩ噴鍦↗DOM涓敤Comment綾繪潵鎶借薄錛汿ext浠h〃浜唜ml涓殑鏂囨湰鍊鹼紝濡傚厓绱犲睘鎬х殑鍊箋佸厓绱犵殑鍊箋佹敞閲婄殑鍐呭絳夛紝鐖跺厓绱犵殑Text涓哄瓙鍏冪礌鍜屽肩粍鎴愮殑涓詫紝浣跨敤Text綾誨彲浠ユ柟渚跨殑琛ㄧず涓浜涚壒孌婂瓧絎?濡傦細

Element element = new Element("name");

Text text = new Text("AAA.<銆丅BB/>.<CCC>");

element.addContent(text);

鍊煎緱涓鎻愮殑鏄疎lement鐨勬柟娉昦ddContent(Content content),鍥犲弬鏁版槸鎶借薄鐖剁被Content錛屾墍浠ュ彲浠ユ坊鍔燭ext銆丒lement鍜孋omment絳夛紝濡傛灉娣誨姞鐨勬槸Text鍒欒嚜鍔ㄤ綔涓篹lement鐨勬枃鏈鹼紝濡傛灉鏄疎lement鍒欎綔涓篹lement鐨勫瓙鍏冪礌錛屽鏋滄槸Comment鍒欎綔涓篹lement鐨勬敞閲婏紝浣跨敤鍗佸垎鏂逛究銆傚厓绱犵殑鍊煎<name>寰愯緵娉?lt;/name>涓殑“寰愯緵娉?#8221;涔熸槸涓涓拰鍏冪礌騫寵鐨凜ontent瀵硅薄錛圱ext瀵硅薄錛夛紝褰撲嬌鐢‥lement鐨刧etDescendants()鏂規硶鏃跺皢榪斿洖涓涓鍏冪礌鎵鏈夊悗浠g殑榪唬鍣紝榪欎簺鍚庝唬鍖呮嫭Element銆丆omment銆乀ext絳夛紝濡傚厓绱?lt;contact>鐨勫悗浠e寘鎷琫mail銆乵obile銆乫ix-phone涓変釜鍏冪礌浠ュ強榪欎笁涓厓绱犵殑Text鍏?涓悗浠o紝濡傛灉璁$畻鍚庝唬鏃舵湁鐖跺瓙宓屽鍒欏簲娉ㄦ剰錛岀埗鍏冪礌浣滀負涓涓悗浠o紝鍏跺祵濂楃殑瀛愬厓绱犱綔涓哄彟涓涓悗浠c?/font>

鍒氭墠鎻愬埌鏍稿績綾婚兘鍖呭惈鍦╫rg.jdom鍖呬笅錛宩dom榪樺寘鍚簡org.jdom.input鍜宱rg.jdom.output涓や釜鍖呭垎鍒潵澶勭悊xml鍐呭鐨勮緭鍏ヨ緭鍑恒傚綋瑕佽鍙杧ml璧勬簮鏃舵垜浠氬父浣跨敤input鍖呬笅鐨凷AXBuilder綾諱粠杈撳叆嫻佹瀯寤篸om瀵硅薄錛屽綋璧勬簮鍔犺澆鍚庡父鐢ㄧ殑鍋氭硶鏄湪鍐呭瓨涓紦瀛橈紝榪欐牱鍚庣畫鐨勬煡鎵句慨鏀圭瓑鎿嶄綔灝遍潪甯稿揩銆傛枃妗e姞杞藉悗鍐呭瓨鐨勪腑鍚勪釜鍏冪礌鏄褰曟湁鍚勮嚜鐨勪綅緗拰鍏崇郴鐨勶紝鍗充繚鎸佹湁涓婁笅鏂囩幆澧冪殑銆傚鏋滄兂瑕佸垹闄や竴孌靛唴瀹癸紙Element Comment Text錛夛紝鍙敤璋冪敤璇ュ唴瀹圭殑detach鏂規硶鍗沖彲錛岃繖鏍峰厓绱犲嵆鍜屾枃妗h劚紱誨叧緋諱簡錛屽啀瀵規枃妗h繘琛岄亶鍘嗘垨鑰呮寔涔呭寲鍒扮鐩樹笂鏃舵父紱葷殑鍏冪礌灝變笉鍙浜嗐侸dom鐨勮緭鍑虹被鍖呮嫭XMLOutputter銆丏OMOutputter銆丼AXOutputter銆傛渶甯哥敤鐨勬槸XMLOutputter錛岄氳繃瀹冨彲浠ュ皢dom瀵硅薄杈撳嚭鍒版寚瀹氱殑杈撳嚭嫻侊紝騫朵笖鍙互鎸囧畾鎵杈撳嚭xml鏂囦歡鐨勬牸寮忥紝姣斿緙╄繘鐨勬牱寮忕瓑銆侱OMOutputter杈撳嚭org.w3c.dom.Document瀵硅薄錛岀敤浜嶫DOM瀵硅薄鍚寃3c dom瀵硅薄杞崲錛孲AXOutputter鍙互娉ㄥ唽鍥炶皟鍑芥暟鏉ュ鐞嗙浉搴旂殑sax浜嬩歡銆?/font>


涓涓嬬ず渚嬩唬鐮佸疄鐜頒竴涓父鐢ㄧ殑璇誨彇閰嶇疆鏂囦歡騫朵笖鍏佽鏇存敼鍚庡悓姝ュ埌紓佺洏鐨勬搷浣滐細
<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    package sinpo.usagedemo;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URL;
    import java.util.List;

    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.Format;
    import org.jdom.output.XMLOutputter;

    /**
     * 璇誨彇閰嶇疆鏂囦歡錛屽茍涓斾慨鏀瑰悗鍙婃椂鍚屾鍒扮鐩?/font>
     @author 寰愯緵娉?sinpo.xu@hotmail.com) 
     * Oct 23, 2008
     */
    public class Configuration {

        private Element root = null;

        private Document dom = null;

        private static final String resourceName = "/config.xml";

        private static Configuration _INSTANCE = null;

        public static synchronized Configuration getInstance() {
            if (_INSTANCE == null) {
                _INSTANCE = new Configuration();
            }

            return _INSTANCE;
        }

        private Configuration() {
            load();
        }

        public String getConfig(String configName) {
            String configValue = null;
            Element found = findRecursively(configName, root);
            if (found != null) {
                configValue = found.getText();
            }
            return configValue;
        }

        public void updateConfig(String configName, String newValue)
                throws IOException {
            Element found = findRecursively(configName, root);
            if (found != null) {
                found.setText(newValue);
            else {
                Element configNode = new Element(configName);
                configNode.addContent(newValue);
                // also: configNode.setText(newValue);
                root.addContent(configNode);
            }
            sync();
        }

        public void deleteConfig(String configNamethrows IOException {
            Element found = findRecursively(configName, root);
            if (found != null) {
                found.detach();
            }
            sync();
        }
        
        private void load() {
            SAXBuilder builder = new SAXBuilder();
            InputStream source = getClass().getResourceAsStream(resourceName);
            try {
                dom = builder.build(source);
                root = dom.getRootElement();
            catch (Exception e) {
                e.printStackTrace();
            }
        }

        // 閫掑綊鏌ユ壘. 鍦ㄦ寚瀹氱殑鐖惰妭鐐逛笅鏌ユ壘鍙跺瓙鍏冪礌
        private Element findRecursively(String name, Element parent) {
            Element found = null;
            List<Element> children = parent.getChildren();
            if (children != null) {
                for (int i = 0; i < children.size(); i++) {
                    Element element = children.get(i);
                    String tmpName = element.getName();
                    if ((name.equals(tmpName)) && (!hasChild(element))) {
                        return element;
                    }
                }

                for (int i = 0; i < children.size(); i++) {
                    Element element = children.get(i);
                    if (hasChild(element)) {
                        found = findRecursively(name, element);
                        if (found != null) {
                            return found;
                        }
                    }
                }
            }

            return found;
        }

        private boolean hasChild(Element element) {
            boolean hasChild = false;
            List children = element.getChildren();
            if ((children != null&& (children.size() 0)) {
                hasChild = true;
            }

            return hasChild;
        }

        private void sync() throws IOException {
            Format format = Format.getPrettyFormat();
            XMLOutputter outputter = new XMLOutputter(format);
            File file = null;
            URL url = getClass().getResource(resourceName);
            if (url == null) {
                file = new File(resourceName);
            else {
                file = new File(url.getPath());

                OutputStream out = null;
                try {
                    out = new FileOutputStream(file);
                    outputter.output(dom, out);
                    out.close();
                    out = null;
                catch (Exception e) {
                    e.printStackTrace();
                    if (out != null) {
                        out.close();
                    }
                }
            }
        }
    }
    主站蜘蛛池模板: 黄色免费在线网站| 黄网址在线永久免费观看 | 国内精品免费在线观看 | 鲁死你资源站亚洲av| 亚洲精品国产字幕久久不卡| 亚洲人成免费电影| 永久在线毛片免费观看| 一级毛片一级毛片免费毛片| 亚洲女人初试黑人巨高清| 成年大片免费视频| 成人毛片100免费观看| wwwxxx亚洲| 精品久久香蕉国产线看观看亚洲| 噼里啪啦免费观看高清动漫4| 理论片在线观看免费| 亚洲精品国产免费| 亚洲精品亚洲人成在线观看下载 | 亚洲免费精彩视频在线观看| 亚洲综合久久夜AV | 亚洲成?v人片天堂网无码| 国产真实伦在线视频免费观看| 亚洲国产精品免费观看| 免费看成人AA片无码视频羞羞网| 日本免费中文字幕| 国产精品99久久免费观看| 免费观看久久精彩视频| a级毛片100部免费观看| a级成人毛片免费视频高清| 久久久受www免费人成| fc2成年免费共享视频网站| 一级午夜a毛片免费视频| 一个人免费观看www视频| 国产成人无码精品久久久免费| 日本免费精品一区二区三区 | 国产人成免费视频| 免费成人黄色大片| 亚洲午夜激情视频| 国产成人亚洲精品青草天美| 亚洲AV日韩AV天堂久久| 亚洲视频手机在线| 亚洲中文字幕日本无线码|

    ]]>
    涔熻皥綰跨▼鐨勪紤鐪犱笌絳夊緟http://www.tkk7.com/sinpo/archive/2008/10/22/236061.html寰愯緵娉?/dc:creator>寰愯緵娉?/author>Wed, 22 Oct 2008 15:26:00 GMThttp://www.tkk7.com/sinpo/archive/2008/10/22/236061.htmlhttp://www.tkk7.com/sinpo/comments/236061.htmlhttp://www.tkk7.com/sinpo/archive/2008/10/22/236061.html#Feedback0http://www.tkk7.com/sinpo/comments/commentRss/236061.htmlhttp://www.tkk7.com/sinpo/services/trackbacks/236061.html 鍏充簬綰跨▼闂寸殑浜や簰鍜屽叡浜暟鎹氬父鏈夎疆璇㈠拰閫氱煡鏈哄埗銆備竴涓嬩婦渚嬭鏄庯細Thread1鍜孴hread2鍏變韓涓鍧楁暟鎹甋hareData錛孴hread1浣跨敤鏁版嵁錛孴hread2鏇存柊鏁版嵁銆傚綋Thread1浣跨敤鏁版嵁鏃跺彂鐜版暟鎹病鏈夋洿鏂板氨鍙互鍏堜紤鐪狅紙sleep錛堬級錛変竴孌墊椂闂寸劧鍚庡啀鍘誨垽鏂槸鍚︽洿鏂幫紝濡傛鍙嶅鐩村埌鏁版嵁鍙敤錛岃繖灝辨槸鎵榪扮殑杞鏈哄埗銆傚彲浠ョ湅鍑鴻疆璇㈡満鍒墮渶瑕佷笉鏂殑杞鏁版嵁鐘舵侊紝寰堣楄垂璧勬簮錛涘綋閲囩敤閫氱煡鏈哄埗鏃惰繃紼嬫槸榪欐牱鐨勶紝Thread1鍙戠幇鏁版嵁涓嶅彲鐢ㄥ氨鍦⊿hareData涓婄瓑寰咃紙ShareData.wait()錛夛紝褰揟hread2鏇存柊鏁版嵁鍚庡氨閫氱煡鎵鏈夊湪ShareData涓婄瓑寰呯殑綰跨▼錛圫hareData.notifyAll())錛岃繖鏍稵hread1鍙楀埌閫氱煡緇х畫榪愯銆?/font>

    鍏充簬絳夊緟鍜屼紤鐪犺繕鏈夊彟涓涓尯鍒氨鏄綋綰跨▼絳夊緟鏃訛紝璇ョ嚎紼嬮攣瀹氱殑璧勬簮鏄噴鏀炬帀鐨勶紝榪欐椂鍏跺畠綰跨▼鏄彲浠ラ攣瀹氳繖浜涜祫婧愮殑錛屽綋綰跨▼琚敜閱掓垨鑰呯瓑寰呮椂闄愬埌鏃剁嚎紼嬮噸鏂拌幏鍙栬祫婧愭墠鑳界戶緇繍琛岋紱鑰屽綋綰跨▼浼戠湢鏃剁嚎紼嬮攣瀹氱殑璧勬簮鏄笉琚噴鏀劇殑銆?/font>

    榪樻湁涓鐐瑰氨鏄鍦ㄥ璞ock涓婄瓑寰呮椂鏄繀欏誨厛瑕佽幏鍙杔ock鐨勫璞¢攣鎵嶈兘榪涜鐨勶紝鍗沖繀欏昏綾諱技涓嬮潰鐨勯昏緫 synchronized錛坙ock){ lock.wait()}

    浠ヤ笅涓轟竴涓畝鍗曠殑紺轟緥錛?/font>

    package  sinpo.usagedemo;

    /**
      * 璇ヤ緥瀛愯鏄庣嚎紼嬩紤鐪犱笌絳夊緟浠ュ強娉ㄦ剰浜嬮」銆?/font>
     
      @author  寰愯緵娉?sinpo.xu@hotmail.com) 
      * Oct 22, 2008
      */
    public class  PendingThreadDemo  {
         public  Console console =  new  Console () ;
         private  void  writeToConsole1 () {
             synchronized ( console ){
                 try  {
                     Thread.sleep ( 1000 ) ; //NOTE:sleep鏃跺茍鏈噴鏀綾onsole鍒殑綰跨▼鏄笉鑳介攣瀹歝onsole鐨?/font>
                     //TODO do things
                 catch  ( InterruptedException e ) {
                     e.printStackTrace () ;
                 }
             }
         }
        
         private  void  writeToConsole2 () {
             synchronized ( console ){
                 try  {
                     console.wait ( 1 * 1000 ) ; //NOTE:wait鏃跺埆鐨勭嚎紼嬫槸鍙互閿佸畾console鐨?/font>
                     //TODO do things
                 catch  ( InterruptedException e ) {
                     e.printStackTrace () ;
                 }
             }
         }
    }
    //鎺у埗鍙扮被
    class  Console  {
         //TODO implements me
    }


    ]]>
    姹傚姪錛氭庝箞璐翠唬鐮佹墠鑳戒繚鎸佷唬鐮佺殑鏍煎紡鍛http://www.tkk7.com/sinpo/archive/2008/10/20/235554.html寰愯緵娉?/dc:creator>寰愯緵娉?/author>Mon, 20 Oct 2008 14:42:00 GMThttp://www.tkk7.com/sinpo/archive/2008/10/20/235554.htmlhttp://www.tkk7.com/sinpo/comments/235554.htmlhttp://www.tkk7.com/sinpo/archive/2008/10/20/235554.html#Feedback2http://www.tkk7.com/sinpo/comments/commentRss/235554.htmlhttp://www.tkk7.com/sinpo/services/trackbacks/235554.html 楹葷儲鏈夎皝鐭ラ亾鐨勫憡鐭ヤ竴涓嬨傘傘?/span>
    浠婂ぉ緇堜簬鎵懼埌涓涓笉閿欑殑宸ュ叿錛岃兘灝嗙敤eclipse絳夌紪杈戠殑java浠g爜鍋氭垚涓鏍烽鏍肩殑html鏍煎紡錛岃瘯鐢ㄤ簡鎸哄ソ鐢ㄧ殑錛岃阿璋?a >Java2Html鍥㈤槦銆?

    ]]>Java NIO瀛︿範-UDP鐨勪緥瀛?/title><link>http://www.tkk7.com/sinpo/archive/2008/10/20/235553.html</link><dc:creator>寰愯緵娉?/dc:creator><author>寰愯緵娉?/author><pubDate>Mon, 20 Oct 2008 14:38:00 GMT</pubDate><guid>http://www.tkk7.com/sinpo/archive/2008/10/20/235553.html</guid><wfw:comment>http://www.tkk7.com/sinpo/comments/235553.html</wfw:comment><comments>http://www.tkk7.com/sinpo/archive/2008/10/20/235553.html#Feedback</comments><slash:comments>11</slash:comments><wfw:commentRss>http://www.tkk7.com/sinpo/comments/commentRss/235553.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sinpo/services/trackbacks/235553.html</trackback:ping><description><![CDATA[<div id="rd9pzjt" class="Section0" style="layout-grid:15.6000pt;"> <p class="p0" style="margin-bottom:0pt; margin-top:0pt; "> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'瀹嬩綋'; "> <font face="瀹嬩綋">榪欏嚑澶╅渶瑕佸疄鐜頒竴涓簳灞傚熀浜嶶DP鐨勫崗璁紝璇ュ崗璁簳灞備嬌鐢║DP浼犺緭浣嗘槸鍏鋒湁鎷ュ鎺у埗銆佽秴鏃墮噸鍙戙佹暟鎹‘璁ょ瓑鍔熻兘鍙堟瘮TCP綆鍗?錛圧UDP錛孯eliable UDP錛夈傚湪瀹炵幇鍗忚搴曞眰鐨刄DP鏈嶅姟鏃跺噯澶囦嬌鐢↗ava鐨凬IO錛屽湪緗戜笂鏌ヨ祫鏂欓兘鏄互TCP涓轟緥璁茬殑錛屼簬鏄嚜宸辯爺絀朵簡涓涓嬪熀浜嶶DP鐨凬IO銆?/font> </span> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'瀹嬩綋'; "> <o:p> </o:p> </span> </p> <p class="p0" style="margin-bottom:0pt; margin-top:0pt; "> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'瀹嬩綋'; ">NIO<font face="瀹嬩綋">鐨勬濊礬鏄熀浜庡璺夋嫨鐨勶紝鍗崇敱鍘熸潵鐨勬瘡涓繛鎺ラ兘鐢變竴涓嚎紼嬫潵絳夊緟娑堟伅錛屾敼涓烘瘡涓繛鎺ラ兘鍦ㄩ夋嫨鍣ㄤ笂娉ㄥ唽錛岀敱閫夋嫨鍣ㄦ潵絳夊緟銆傚綋鐒禢IO寮曞叆浜嗗緢澶氭柊鐨勬蹇碉紝濡侰hannel錛孊uffer銆丆harset銆丼elector絳夛紝浣垮緱緙栫▼鏇寸畝媧併佹洿闈㈠悜瀵硅薄鍖栥?/font></span> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'瀹嬩綋'; "> <o:p> </o:p> </span> </p> <p class="p0" style="margin-bottom:0pt; margin-top:0pt; "> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'瀹嬩綋'; "> <font face="瀹嬩綋">涓嬮潰璐村嚭鐢∟IO API鏀歸犳垚UDP紺轟緥浠g爜錛屾敞鎰忓叾涓嬌鐢–harset鏉ョ紪鐮佽В鐮佺殑榪囩▼錛堝綋鐒禖harset榪樻敮鎸佸緢澶氬叾浠栫紪鐮佷笉浠呭眬闄愪簬榛樿緙栫爜錛変互鍙夿uffer鐨勪嬌鐢ㄣ?/font> </span> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'瀹嬩綋'; "> <o:p> </o:p> </span> </p> </div> <!-- ======================================================== --> <!-- = Java Sourcecode to HTML automatically converted code = --> <!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --> <!-- = Further information: http://www.java2html.de = --> <div align="left" class="java"> <table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff"> <tbody> <tr> <!-- start source code --> <td nowrap="nowrap" valign="top" align="left"> <code> <font color="#7f0055"> <strong>package </strong> </font> <font color="#000000">sinpo.usagedemo;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.DatagramSocket;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.InetSocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.SocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.ByteBuffer;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.CharBuffer;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.DatagramChannel;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.SelectionKey;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.Selector;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.charset.Charset;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Iterator;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Set;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#3f5fbf">/**</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">* </font> <font color="#7f9fbf">@author </font> <font color="#3f5fbf">寰愯緵娉?sinpo.xu@hotmail.com) Oct 19, 2008</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">*/</font> <br /> <font color="#7f0055"> <strong>public class </strong> </font> <font color="#000000">UDPServer </font> <font color="#7f0055"> <strong>extends </strong> </font> <font color="#000000">Thread </font> <font color="#000000">{</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>public </strong> </font> <font color="#7f0055"> <strong>void </strong> </font> <font color="#000000">run</font> <font color="#000000">() {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">Selector selector = </font> <font color="#7f0055"> <strong>null</strong> </font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff"> </font> <font color="#000000">DatagramChannel channel = DatagramChannel.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">DatagramSocket socket = channel.socket</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">channel.configureBlocking</font> <font color="#000000">(</font> <font color="#7f0055"> <strong>false</strong> </font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">socket.bind</font> <font color="#000000">(</font> <font color="#7f0055"> <strong>new </strong> </font> <font color="#000000">InetSocketAddress</font> <font color="#000000">(</font> <font color="#990000">5057</font> <font color="#000000">))</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">selector = Selector.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">channel.register</font> <font color="#000000">(</font> <font color="#000000">selector, SelectionKey.OP_READ</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">ByteBuffer byteBuffer = ByteBuffer.allocate</font> <font color="#000000">(</font> <font color="#990000">65536</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#7f0055"> <strong>true</strong> </font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>int </strong> </font> <font color="#000000">eventsCount = selector.select</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">eventsCount > </font> <font color="#990000">0</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">Set selectedKeys = selector.selectedKeys</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">Iterator iterator = selectedKeys.iterator</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#000000">iterator.hasNext</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">SelectionKey sk = </font> <font color="#000000">(</font> <font color="#000000">SelectionKey</font> <font color="#000000">) </font> <font color="#000000">iterator.next</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">iterator.remove</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">sk.isReadable</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">DatagramChannel datagramChannel = </font> <font color="#000000">(</font> <font color="#000000">DatagramChannel</font> <font color="#000000">) </font> <font color="#000000">sk</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.channel</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">SocketAddress sa = datagramChannel</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.receive</font> <font color="#000000">(</font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">byteBuffer.flip</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#3f7f5f">// 嫻嬭瘯錛氶氳繃灝嗘敹鍒扮殑ByteBuffer棣栧厛閫氳繃緙虹渷鐨勭紪鐮佽В鐮佹垚CharBuffer 鍐嶈緭鍑?/font> <br /> <font color="#ffffff"> </font> <font color="#000000">CharBuffer charBuffer = Charset.defaultCharset</font> <font color="#000000">()</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.decode</font> <font color="#000000">(</font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">System.out.println</font> <font color="#000000">(</font> <font color="#2a00ff">"receive message:"</font> <br /> <font color="#ffffff"> </font> <font color="#000000">+ charBuffer.toString</font> <font color="#000000">())</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">byteBuffer.clear</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">String echo = </font> <font color="#2a00ff">"This is the reply message from 鏈嶅姟鍣ㄣ?</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">ByteBuffer buffer = Charset.defaultCharset</font> <font color="#000000">()</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.encode</font> <font color="#000000">(</font> <font color="#000000">echo</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">datagramChannel.write</font> <font color="#000000">(</font> <font color="#000000">buffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>public static </strong> </font> <font color="#7f0055"> <strong>void </strong> </font> <font color="#000000">main</font> <font color="#000000">(</font> <font color="#000000">String</font> <font color="#000000">[] </font> <font color="#000000">args</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>new </strong> </font> <font color="#000000">UDPServer</font> <font color="#000000">()</font> <font color="#000000">.start</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#000000">}</font> </code> </td> <!-- end source code --> </tr> </tbody> </table> </div> <!-- = END of automatically generated HTML code = --> <!-- ======================================================== --> Client <br /> <!-- ======================================================== --> <!-- = Java Sourcecode to HTML automatically converted code = --> <!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --> <!-- = Further information: http://www.java2html.de = --> <div align="left" class="java"> <table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff"> <tbody> <tr> <!-- start source code --> <td nowrap="nowrap" valign="top" align="left"> <code> <font color="#7f0055"> <strong>package </strong> </font> <font color="#000000">sinpo.usagedemo;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.InetSocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.SocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.ByteBuffer;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.DatagramChannel;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.SelectionKey;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.Selector;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.charset.Charset;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Iterator;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Set;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#3f5fbf">/**</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">* </font> <font color="#7f9fbf">@author </font> <font color="#3f5fbf">寰愯緵娉?sinpo.xu@hotmail.com)</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">* Oct 19, 2008</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">*/</font> <br /> <font color="#7f0055"> <strong>public class </strong> </font> <font color="#000000">UDPClient </font> <font color="#7f0055"> <strong>extends </strong> </font> <font color="#000000">Thread </font> <font color="#000000">{</font> <br /> <font color="#ffffff">    </font> <font color="#7f0055"> <strong>public </strong> </font> <font color="#7f0055"> <strong>void </strong> </font> <font color="#000000">run</font> <font color="#000000">() {</font> <br /> <font color="#ffffff">        </font> <font color="#000000">DatagramChannel channel = </font> <font color="#7f0055"> <strong>null</strong> </font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">Selector selector = </font> <font color="#7f0055"> <strong>null</strong> </font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel = DatagramChannel.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.configureBlocking</font> <font color="#000000">(</font> <font color="#7f0055"> <strong>false</strong> </font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">SocketAddress sa = </font> <font color="#7f0055"> <strong>new </strong> </font> <font color="#000000">InetSocketAddress</font> <font color="#000000">(</font> <font color="#2a00ff">"localhost"</font> <font color="#000000">, </font> <font color="#990000">5057</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.connect</font> <font color="#000000">(</font> <font color="#000000">sa</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">            </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff">        </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff">            </font> <font color="#000000">selector = Selector.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.register</font> <font color="#000000">(</font> <font color="#000000">selector, SelectionKey.OP_READ</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.write</font> <font color="#000000">(</font> <font color="#000000">Charset.defaultCharset</font> <font color="#000000">()</font> <font color="#000000">.encode</font> <font color="#000000">(</font> <font color="#2a00ff">"Tell me your time"</font> <font color="#000000">))</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">            </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">}</font> <br /> <font color="#ffffff">        </font> <br /> <font color="#ffffff">        </font> <font color="#000000">ByteBuffer byteBuffer = ByteBuffer.allocate</font> <font color="#000000">(</font> <font color="#990000">100</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#7f0055"> <strong>true</strong> </font> <font color="#000000">) {</font> <br /> <font color="#ffffff">            </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff">                </font> <font color="#7f0055"> <strong>int </strong> </font> <font color="#000000">eventsCount = selector.select</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">eventsCount > </font> <font color="#990000">0</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">                    </font> <font color="#000000">Set selectedKeys = selector.selectedKeys</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                    </font> <font color="#000000">Iterator iterator = selectedKeys.iterator</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                    </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#000000">iterator.hasNext</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff">                        </font> <font color="#000000">SelectionKey sk = </font> <font color="#000000">(</font> <font color="#000000">SelectionKey</font> <font color="#000000">) </font> <font color="#000000">iterator.next</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                        </font> <font color="#000000">iterator.remove</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                        </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">sk.isReadable</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">DatagramChannel datagramChannel = </font> <font color="#000000">(</font> <font color="#000000">DatagramChannel</font> <font color="#000000">) </font> <font color="#000000">sk</font> <br /> <font color="#ffffff">                                    </font> <font color="#000000">.channel</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">datagramChannel.read</font> <font color="#000000">(</font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">byteBuffer.flip</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <br /> <font color="#ffffff">                            </font> <font color="#3f7f5f">//TODO 灝嗘姤鏂囪漿鍖栦負RUDP娑堟伅騫惰皟鐢≧UDP鍗忚澶勭悊鍣ㄦ潵澶勭悊</font> <br /> <font color="#ffffff">                            </font> <br /> <font color="#ffffff">                            </font> <font color="#000000">System.out.println</font> <font color="#000000">(</font> <font color="#000000">Charset.defaultCharset</font> <font color="#000000">()</font> <font color="#000000">.decode</font> <font color="#000000">(</font> <br /> <font color="#ffffff">                                    </font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">.toString</font> <font color="#000000">())</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">byteBuffer.clear</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">datagramChannel.write</font> <font color="#000000">(</font> <font color="#000000">Charset.defaultCharset</font> <font color="#000000">()</font> <br /> <font color="#ffffff">                                    </font> <font color="#000000">.encode</font> <font color="#000000">(</font> <font color="#2a00ff">"Tell me your time"</font> <font color="#000000">))</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                        </font> <font color="#000000">}</font> <br /> <font color="#ffffff">                    </font> <font color="#000000">}</font> <br /> <font color="#ffffff">                </font> <font color="#000000">}</font> <br /> <font color="#ffffff">            </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">                </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">}</font> <br /> <font color="#ffffff">        </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff">    </font> <font color="#000000">}</font> <br /> <font color="#000000">}</font> </code> </td> <!-- end source code --> </tr> </tbody> </table> </div> <!-- = END of automatically generated HTML code = --> <!-- ======================================================== --> <img src ="http://www.tkk7.com/sinpo/aggbug/235553.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sinpo/" target="_blank">寰愯緵娉?/a> 2008-10-20 22:38 <a href="http://www.tkk7.com/sinpo/archive/2008/10/20/235553.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>妯″紡瀛︿範-鍩轟簬鎺ュ彛鐨勬ā寮?/title><link>http://www.tkk7.com/sinpo/archive/2008/10/20/235541.html</link><dc:creator>寰愯緵娉?/dc:creator><author>寰愯緵娉?/author><pubDate>Mon, 20 Oct 2008 13:48:00 GMT</pubDate><guid>http://www.tkk7.com/sinpo/archive/2008/10/20/235541.html</guid><wfw:comment>http://www.tkk7.com/sinpo/comments/235541.html</wfw:comment><comments>http://www.tkk7.com/sinpo/archive/2008/10/20/235541.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/sinpo/comments/commentRss/235541.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sinpo/services/trackbacks/235541.html</trackback:ping><description><![CDATA[     鎽樿:   <a href='http://www.tkk7.com/sinpo/archive/2008/10/20/235541.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/sinpo/aggbug/235541.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sinpo/" target="_blank">寰愯緵娉?/a> 2008-10-20 21:48 <a href="http://www.tkk7.com/sinpo/archive/2008/10/20/235541.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鐢–lassLoader璇誨彇璧勬簮鏂囦歡http://www.tkk7.com/sinpo/archive/2008/10/19/235328.html寰愯緵娉?/dc:creator>寰愯緵娉?/author>Sun, 19 Oct 2008 12:36:00 GMThttp://www.tkk7.com/sinpo/archive/2008/10/19/235328.htmlhttp://www.tkk7.com/sinpo/comments/235328.htmlhttp://www.tkk7.com/sinpo/archive/2008/10/19/235328.html#Feedback0http://www.tkk7.com/sinpo/comments/commentRss/235328.htmlhttp://www.tkk7.com/sinpo/services/trackbacks/235328.htmlClass綾葷殑getResourceAsStream(String resourcePath);
    ClassLoader綾葷殑getResourceAsStream(String resourcePath)
    Class綾葷殑璇ユ柟娉曟渶緇堣繕鏄媧劇粰ClassLoader鐨刧etResourceAsStream鏂規硶錛屼絾鏄嬌鐢ㄤ腑鍙戠幇Class#getResourceAsStream()浣跨敤鐨勬槸緇濆璺緞錛堜互/寮澶達級錛岃孋lassLoader#getResourceAsStream()浣跨敤鐨勭浉瀵硅礬寰勩?
    propterty鏂囦歡緇忓父鏀懼湪綾昏礬寰勭殑鏍硅礬寰勪笅錛堟渶欏跺眰鍖呯殑涓婂眰鐩綍錛屽classes錛夛紝榪欐牱鍔犺澆property鏂囦歡鏃跺氨鍙互鍏堢敤Class#getResourceAsStream鏂規硶鑾峰彇杈撳叆婧愶紝鍐嶄粠璇ヨ緭鍏ユ簮load鍚別ntry銆?/div> code piece:
    package sinpo.usagedemo;

    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.Properties;

    import junit.framework.TestCase;

    /**
     @author 寰愯緵娉?sinpo.xu@hotmail.com)
     * Oct 19, 2008
     */
    public class LoadResource extends TestCase {
        public void test() throws Exception {
            //usage 1錛?#160;use absolute path (mostly used)
            InputStream in1 = this.getClass().getResourceAsStream("/sinpo/test2.properties");
            //usage 2: use relative path
            InputStream in2 = this.getClass().getClassLoader().getResourceAsStream("sinpo/test2.properties");
            //usage 3: use system class path
            InputStream in3 = ClassLoader.getSystemResourceAsStream("system.properties");
            
            //灝嗚鍙栫殑璧勬簮浣滀負Properties鐨勮緭鍏ユ簮
            Properties props = new Properties();
            props.load(in1);
            String propValue = props.getProperty("propKey");
            System.out.println(propValue);
            
            //灝嗚鍙栫殑璧勬簮浣滀負鏂囨湰杈撳嚭
            InputStreamReader reader = new InputStreamReader(in1);
            BufferedReader bReader = new BufferedReader(reader);
            String content = bReader.readLine();
            //杈撳嚭絎竴琛屽唴瀹?/font>
            System.out.println(content);
            
            //TODO close them
        }
    }


    ]]>