°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
¡¡¡¡¡¡¡¡IO¡£close£¨in£©£»¡¡¡¡
¡¡¡¡¡¡¡¡dm¡£writePackedFile£¨args£§2£§£©£»¡¡¡¡
¡¡¡¡£ý¡¡¡¡
¡¡¡¡private¡¡static¡¡void¡¡¡¡¡¡
¡¡¡¡extractPackedFile£¨String£§£§¡¡args£©¡¡£û¡¡¡¡
¡¡¡¡¡¡¡¡if£¨args¡£length¡¡==¡¡2£©¡¡//¡¡Alternate¡¡directory¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡dm¡¡=¡¡new¡¡DirMap£¨args£§1£§£©£»¡¡¡¡
¡¡¡¡¡¡¡¡else¡¡//¡¡Current¡¡directory¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡dm¡¡=¡¡new¡¡DirMap£¨£©£»¡¡¡¡
¡¡¡¡¡¡¡¡in¡¡=¡¡IO¡£disOpen£¨args£§0£§£©£»¡¡¡¡
¡¡¡¡¡¡¡¡String¡¡s¡¡=¡¡null£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡629¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡631¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡try¡¡£û¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡s¡¡=¡¡in¡£readLine£¨£©£»¡¡¡¡
¡¡¡¡¡¡¡¡£ý¡¡catch£¨IOException¡¡e£©¡¡£û¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡Pr¡£error£¨¡¨Cannot¡¡read¡¡from¡¡¡¨¡¡£«¡¡in£©£»¡¡¡¡
¡¡¡¡¡¡¡¡£ý¡¡¡¡
¡¡¡¡¡¡¡¡//¡¡Capture¡¡the¡¡separator¡¡used¡¡in¡¡the¡¡system¡¡¡¡
¡¡¡¡¡¡¡¡//¡¡that¡¡packed¡¡the¡¡file£º¡¡¡¡
¡¡¡¡¡¡¡¡if£¨s¡£indexOf£¨¡¨###Old¡¡Separator£º¡¨£©¡¡£¡=¡¡¡1¡¡£©¡¡£û¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡String¡¡oldsep¡¡=¡¡s¡£substring£¨¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨###Old¡¡Separator£º¡¨¡£length£¨£©£©£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡oldsep¡¡=¡¡oldsep¡£substring£¨¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡0£»¡¡oldsep¡£¡¡indexOf£¨'#'£©£©£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡SourceCodeFile¡£oldsep¡¡=¡¡oldsep£»¡¡¡¡
¡¡¡¡¡¡¡¡£ý¡¡¡¡
¡¡¡¡¡¡¡¡SourceCodeFile¡¡sf¡¡=¡¡new¡¡SourceCodeFile£¨in£©£»¡¡¡¡
¡¡¡¡¡¡¡¡while£¨sf¡£hasFile£¨£©£©¡¡£û¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡dm¡£add£¨sf£©£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡sf¡¡=¡¡new¡¡SourceCodeFile£¨in£©£»¡¡¡¡
¡¡¡¡¡¡¡¡£ý¡¡¡¡
¡¡¡¡¡¡¡¡dm¡£write£¨£©£»¡¡¡¡
¡¡¡¡£ý¡¡¡¡
£ý¡¡///£º~¡¡¡¡
¡¡¡¡
ÎÒÃÇ×¢Òâµ½¡¡package¡¡Óï¾äÒѾ×÷ΪעÊͱêÖ¾³öÀ´ÁË¡£ÓÉÓÚÕâÊDZ¾ÕµĵÚÒ»¸ö³ÌÐò£¬ËùÒÔpackage¡¡Óï¾äÊDZØÐè¡¡
µÄ£¬ÓÃËü¸æËßCodePackager¡¡ÒѸĻ»µ½ÁíÒ»Õ¡£µ«ÊÇ°ÑËü·ÅÈë°üÀïÈ´»á³ÉΪһ¸öÎÊÌâ¡£µ±ÎÒÃÇ´´½¨Ò»¸ö°üµÄʱ¡¡
ºò£¬ÐèÒª½«½á¹û³ÌÐòͬһ¸öÌض¨µÄĿ¼½á¹¹ÁªÏµÔÚÒ»Æð£¬ÕâÒ»×ö·¨¶Ô±¾ÊéµÄ´ó¶àÊýÀý×Ó¶¼ÊÇÊÊÓõġ£µ«ÔÚÕâ¡¡
ÀCodePackager¡¡³ÌÐò±ØÐëÔÚÒ»¸öרÓõÄĿ¼Àï±àÒëºÍÔËÐУ¬ËùÒÔ¡¡package¡¡Óï¾ä×÷ΪעÊͱê¼Ç³öÈ¥¡£µ«¶Ô¡¡
CodePackager¡¡À´Ëµ£¬Ëü¡°¿´ÆðÀ´¡±ÒÀÈ»ÏóÒ»¸öÆÕͨµÄpackage¡¡Óï¾ä£¬ÒòΪ³ÌÐò»¹²»ÊÇÌرð¸´ÔÓ£¬²»ÄÜÕì²éµ½¡¡
¶àÐÐ×¢ÊÍ£¨Ã»ÓбØÒª×öµÃÕâô¸´ÔÓ£¬ÕâÀïÖ»ÒªÇó·½±ã¾ÍÐУ©¡£¡¡¡¡
Í·Á½¸öÀàÊÇ¡°Ö§³Ö£¯¹¤¾ß¡±À࣬×÷ÓÃÊÇʹ³ÌÐòÊ£ÓàµÄ²¿·ÖÔÚ±àдʱ¸ü¼ÓÁ¬¹á£¬Ò²¸ü±ãÓÚÔĶÁ¡£µÚÒ»¸öÊÇPr£¬¡¡
ËüÀàËÆANSI¡¡C¡¡µÄperror¡¡¿â£¬Á½Õ߶¼ÄÜ´òÓ¡³öÒ»Ìõ´íÎóÌáʾÏûÏ¢£¨µ«Í¬Ê±Ò²»áÍ˳ö³ÌÐò£©¡£µÚ¶þ¸öÀཫÎļþ¡¡
µÄ´´½¨¹ý³Ì·â×°ÔÚÄÚ£¬Õâ¸ö¹ý³ÌÒÑÔÚµÚ10Õ½éÉܹýÁË£»´ó¼ÒÒѾ֪µÀ£¬ÕâÑù×öºÜ¿ì¾Í»á±äµÃ·Ç³£ÀÛ׸ºÍÂé¡¡
·³¡£Îª½â¾öÕâ¸öÎÊÌ⣬µÚ¡¡10¡¡ÕÂÌṩµÄ·½°¸ÖÂÁ¦ÓÚÐÂÀàµÄ´´½¨£¬µ«Õâ¶ùµÄ¡°¾²Ì¬¡±·½·¨ÒѾʹÓùýÁË¡£ÔÚÄÇЩ¡¡
·½·¨ÖУ¬Õý³£µÄÎ¥Àý»á±»²¶»ñ£¬²¢ÏàÓ¦µØ½øÐд¦Àí¡£ÕâЩ·½·¨Ê¹Ê£ÓàµÄ´úÂëÏԵøü¼ÓÇåˬ£¬¸üÒ×ÔĶÁ¡£¡¡¡¡
°ïÖú½â¾öÎÊÌâµÄµÚÒ»¸öÀàÊÇSourceCodeFile¡¡£¨Ô´ÂëÎļþ£©£¬Ëü´ú±í±¾ÊéÒ»¸öÔ´ÂëÎļþ°üº¬µÄËùÓÐÐÅÏ¢£¨ÄÚ¡¡
ÈÝ¡¢ÎļþÃûÒÔ¼°Ä¿Â¼£©¡£Ëüͬʱ»¹°üº¬ÁËһϵÁÐString¡¡³£Êý£¬·Ö±ð´ú±íÒ»¸öÎļþµÄ¿ªÊ¼Óë½áÊø£»ÔÚ´ò°üÎļþ¡¡
ÄÚʹÓõÄÒ»¸ö±ê¼Ç£»µ±Ç°ÏµÍ³µÄ»»Ðзû£»Îļþ·¾¶·Ö¸ô·û£¨×¢ÒâÒªÓÃSystem¡£getProperty£¨£©Õì²é±¾µØ°æ±¾ÊÇ¡¡
ʲô£©£»ÒÔ¼°Ò»´ó¶Î°æȨÉùÃ÷£¬ËüÊÇ´ÓÏÂÃæÕâ¸öCopyright¡£txt¡¡ÎļþÀïÌáÈ¡³öÀ´µÄ£º¡¡¡¡
¡¡¡¡
//////////////////////////////////////////////////¡¡¡¡
//¡¡Copyright¡¡£¨c£©¡¡Bruce¡¡Eckel£»¡¡1998¡¡¡¡
//¡¡Source¡¡code¡¡file¡¡from¡¡the¡¡book¡¡¡¨Thinking¡¡in¡¡Java¡¨¡¡¡¡
//¡¡All¡¡rights¡¡reserved¡¡EXCEPT¡¡as¡¡allowed¡¡by¡¡the¡¡¡¡
//¡¡following¡¡statements£º¡¡You¡¡may¡¡freely¡¡use¡¡this¡¡file¡¡¡¡
//¡¡for¡¡your¡¡own¡¡work¡¡£¨personal¡¡or¡¡mercial£©£»¡¡¡¡
//¡¡including¡¡modifications¡¡and¡¡distribution¡¡in¡¡¡¡
//¡¡executable¡¡form¡¡only¡£¡¡Permission¡¡is¡¡granted¡¡to¡¡use¡¡¡¡
//¡¡this¡¡file¡¡in¡¡classroom¡¡situations£»¡¡including¡¡its¡¡¡¡
//¡¡use¡¡in¡¡presentation¡¡materials£»¡¡as¡¡long¡¡as¡¡the¡¡book¡¡¡¡
//¡¡¡¨Thinking¡¡in¡¡Java¡¨¡¡is¡¡cited¡¡as¡¡the¡¡source¡£¡¡¡¡¡¡
//¡¡Except¡¡in¡¡classroom¡¡situations£»¡¡you¡¡may¡¡not¡¡copy¡¡¡¡
//¡¡and¡¡distribute¡¡this¡¡code£»¡¡instead£»¡¡the¡¡sole¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡630¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡632¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
//¡¡distribution¡¡point¡¡is¡¡http£º//BruceEckel¡£¡¡¡¡¡¡
//¡¡£¨and¡¡official¡¡mirror¡¡sites£©¡¡where¡¡it¡¡is¡¡¡¡
//¡¡freely¡¡available¡£¡¡You¡¡may¡¡not¡¡remove¡¡this¡¡¡¡
//¡¡copyright¡¡and¡¡notice¡£¡¡You¡¡may¡¡not¡¡distribute¡¡¡¡
//¡¡modified¡¡versions¡¡of¡¡the¡¡source¡¡code¡¡in¡¡this¡¡¡¡
//¡¡package¡£¡¡You¡¡may¡¡not¡¡use¡¡this¡¡file¡¡in¡¡printed¡¡¡¡
//¡¡media¡¡without¡¡the¡¡express¡¡permission¡¡of¡¡the¡¡¡¡
//¡¡author¡£¡¡Bruce¡¡Eckel¡¡makes¡¡no¡¡representation¡¡about¡¡¡¡
//¡¡the¡¡suitability¡¡of¡¡this¡¡software¡¡for¡¡any¡¡purpose¡£¡¡¡¡
//¡¡It¡¡is¡¡provided¡¡¡¨as¡¡is¡¨¡¡without¡¡express¡¡or¡¡implied¡¡¡¡
//¡¡warranty¡¡of¡¡any¡¡kind£»¡¡including¡¡any¡¡implied¡¡¡¡
//¡¡warranty¡¡of¡¡merchantability£»¡¡fitness¡¡for¡¡a¡¡¡¡
//¡¡particular¡¡purpose¡¡or¡¡non¡infringement¡£¡¡The¡¡entire¡¡¡¡
//¡¡risk¡¡as¡¡to¡¡the¡¡quality¡¡and¡¡performance¡¡of¡¡the¡¡¡¡
//¡¡software¡¡is¡¡with¡¡you¡£¡¡Bruce¡¡Eckel¡¡and¡¡the¡¡¡¡
//¡¡publisher¡¡shall¡¡not¡¡be¡¡liable¡¡for¡¡any¡¡damages¡¡¡¡
//¡¡suffered¡¡by¡¡you¡¡or¡¡any¡¡third¡¡party¡¡as¡¡a¡¡result¡¡of¡¡¡¡
//¡¡using¡¡or¡¡distributing¡¡software¡£¡¡In¡¡no¡¡event¡¡will¡¡¡¡
//¡¡Bruce¡¡Eckel¡¡or¡¡the¡¡publisher¡¡be¡¡liable¡¡for¡¡any¡¡¡¡
//¡¡lost¡¡revenue£»¡¡profit£»¡¡or¡¡data£»¡¡or¡¡for¡¡direct£»¡¡¡¡
//¡¡indirect£»¡¡special£»¡¡consequential£»¡¡incidental£»¡¡or¡¡¡¡
//¡¡punitive¡¡damages£»¡¡however¡¡caused¡¡and¡¡regardless¡¡of¡¡¡¡
//¡¡the¡¡theory¡¡of¡¡liability£»¡¡arising¡¡out¡¡of¡¡the¡¡use¡¡of¡¡¡¡
//¡¡or¡¡inability¡¡to¡¡use¡¡software£»¡¡even¡¡if¡¡Bruce¡¡Eckel¡¡¡¡
//¡¡and¡¡the¡¡publisher¡¡have¡¡been¡¡advised¡¡of¡¡the¡¡¡¡
//¡¡possibility¡¡of¡¡such¡¡damages¡£¡¡Should¡¡the¡¡software¡¡¡¡
//¡¡prove¡¡defective£»¡¡you¡¡assume¡¡the¡¡cost¡¡of¡¡all¡¡¡¡
//¡¡necessary¡¡servicing£»¡¡repair£»¡¡or¡¡correction¡£¡¡If¡¡you¡¡¡¡
//¡¡think¡¡you've¡¡found¡¡an¡¡error£»¡¡please¡¡email¡¡all¡¡¡¡
//¡¡modified¡¡files¡¡with¡¡clearly¡¡mented¡¡changes¡¡to£º¡¡¡¡
//¡¡Bruce@EckelObjects¡£¡£¡¡£¨please¡¡use¡¡the¡¡same¡¡¡¡
//¡¡address¡¡for¡¡non¡code¡¡errors¡¡found¡¡in¡¡the¡¡book£©¡£¡¡¡¡
//////////////////////////////////////////////////¡¡¡¡
¡¡¡¡
´ÓÒ»¸ö´ò°üÎļþÖÐÌáÈ¡Îļþʱ£¬µ±³õËùÓÃϵͳµÄÎļþ·Ö¸ô·ûÒ²»á±ê×¢³öÀ´£¬ÒÔ±ãÓñ¾µØϵͳÊÊÓõķûºÅÌæ»»¡¡
Ëü¡£¡¡¡¡
µ±Ç°ÕµÄ×ÓĿ¼±£´æÔÚ¡¡chapter×Ö¶ÎÖУ¬Ëü³õʼ»¯³Éc02¡¡£¨´ó¼Ò¿É×¢ÒâһϵÚ2¡¡ÕµÄÁбíÕýºÃûÓаüº¬Ò»¸ö¡¡
´ò°üÓï¾ä£©¡£Ö»ÓÐÔÚµ±Ç°ÎļþÀï·¢ÏÖÒ»¸ö¡¡package¡¡£¨´ò°ü£©Óï¾äʱ£¬chapter×ֶβŻᷢÉú¸Ä±ä¡£¡¡¡¡
¡¡¡¡
1¡£¡¡¹¹½¨Ò»¸ö´ò°üÎļþ¡¡¡¡
µÚÒ»¸ö¹¹½¨Æ÷ÓÃÓÚ´Ó±¾ÊéµÄASCII¡¡Îı¾°æÀïÌáÈ¡³öÒ»¸öÎļþ¡£·¢³öµ÷ÓõĴúÂ루ÔÚÁбíÀï½ÏÉîµÄµØ·½£©»á¶Á¡¡
Èë²¢¼ì²éÿһÐУ¬Ö±µ½ÕÒµ½ÓëÒ»¸öÁбíµÄ¿ªÍ·Ïà·ûµÄΪֹ¡£ÔÚÕâ¸öʱºò£¬Ëü¾Í»áн¨Ò»¸öSourceCodeFile¡¡¶Ô¡¡
Ï󣬽«µÚÒ»ÐеÄÄÚÈÝ£¨ÒѾÓɵ÷ÓôúÂë¶ÁÈëÁË£©´«µÝ¸øËü£¬Í¬Ê±»¹Òª´«µÝBufferedReader¡¡¶ÔÏó£¬ÒÔ±ãÔÚÕâ¸ö¡¡
»º³åÇøÖÐÌáÈ¡Ô´ÂëÁбíÊ£ÓàµÄÄÚÈÝ¡£¡¡¡¡
´ÓÕâʱÆ𣬴ó¼Ò»á·¢ÏÖ¡¡String¡¡·½·¨±»Æµ·±ÔËÓá£ÎªÌáÈ¡³öÎļþÃû£¬Ðèµ÷ÓÃsubstring£¨£©µÄ¹ýÔØ°æ±¾£¬ÁîÆä´Ó¡¡
Ò»¸öÆðʼƫÒÆ¿ªÊ¼£¬Ò»Ö±¶Áµ½×Ö´®µÄĩ⣬´Ó¶øÐγÉÒ»¸ö¡°×Ó´®¡±¡£ÎªËã³öÕâ¸öÆðʼË÷Òý£¬ÏÈÒªÓÃlength£¨£©¡¡
µÃ³ö¡¡startMarker¡¡µÄ×ܳ¤£¬ÔÙÓÃtrim£¨£©É¾³ý×Ö´®Í·Î²¶àÓàµÄ¿Õ¸ñ¡