Javaã®ãã¡ã¤ã«æä½ã§ããã¡ã¤ã«ã«æ¸ãè¾¼ãå¦çã¯ãã使ç¨ããã¾ããã©ã®ãããªç¨éã§ããã¡ã¤ã«ã«æ¸ãè¾¼ãåºæ¬çãªæµãã¯å¤ããã¾ããããç¨éå¥ã«å¦çãç°ãªãããã使ãæ¹ããã¾ãã¡ããããªãæ¹ãå¤ãã®ã§ã¯ãªãã§ããããï¼ Javaã§æ¢åã®zipãã¡ã¤ã«ã«ã¨ã³ããªã追å ããæ¹æ³ (3) . 以åãæ¥åã¢ããª(Java)ã§zipãã¡ã¤ã«ã®æä½ãå¿
è¦ã¨ãªã£ããããJavaã«ãããzipå§ç¸®è§£åã«ã¤ãã¦èª¿æ»ãã¾ããã ã¾ããzip4jã使ã£ãå§ç¸®ã»è§£åã«ã¤ãã¦ã説æãã¾ããã ããã§ã¯ãããå°ãæ¥å使ç¨ãèæ
®ãããå®å
¨ãªzipãã¡ã¤ã«è§£åã«ã¤ãã¦èª¬æãã¾ãã ãããã®ã³ã¢ã©ã¤ãã©ãªã¯ java.util.zip ããã±ã¼ã¸ã®ä¸é¨ã§ã - ... 次ã«ãè¤æ°ã®ãã¡ã¤ã«ã1ã¤ã®zipãã¡ã¤ã«ã«å§ç¸®ããæ¹æ³ãè¦ã¦ã¿ã¾ãããã test1.txt 㨠test2.txt ã multiCompressed.zip ã«å§ç¸®ãã¾ãã . åãã¦è³ªåããã¦ããã ãã¾ãã JDK 1.5.0_15 Tomcat 5.5 ç¾å¨ãサーï¾ï¾ï¾ï½¯ï¾ã§ã以ä¸ã®ãããªWEBï½±ï¾ï¾ï¾ãä½æä¸ã§ãã è¤æ°ã®ãã¡ã¤ã«ã§éçºãè¡ãå ´åãimportæã§ä»ã®ãã¡ã¤ã«ã®ã¯ã©ã¹ã使ããã¨ãã§ãããã¯ã©ã¹ãå¢ãã¦ããã¨ãããã±ã¼ã¸ã§ã¾ã¨ããã importï¼ããã±ã¼ã¸ã¨ã¯ã©ã¹ãæå®ãã¦èªã¿è¾¼ããpackageã®æ¬¡ã«è¨è¿°ããã java.util.zipã«ã¤ãã¦éå»ã«ããã¤ã質åããã£ãã®ã§ããã ç¥ããããã¨ããªãã£ãã®ã§è³ªåããã¦ããã ãã¾ã. JAVAã§ãã¡ã¤ã«ãZIPå§ç¸®ãã â . java.util.zip ããã±ã¼ã¸ã使ç¨ãã¦ãã¡ã¤ã«ãZIPå§ç¸®ãã. ZIPæ¸åº«å
ã®ãã¡ã¤ã«ãåæãã. -classpath ã«ã¯ããã©ã«ãåã®ä»ãjarãã¡ã¤ã«åãzipãã¡ã¤ã«åãæå®ãããã¨ãã§ãã¾ãã C:\java>javac -classpath C:\myJavaLib\MyClass.jar Test.java. è¤æ°ã®ããã¹ããã¡ã¤ã«ã®ZIPå. Java ã§ã¯ãZIP å½¢å¼ã GZIP å½¢å¼ã®ãã¼ã¿ã®èªè¾¼ã¿ãä½æãæ´æ°ãè¡ãããã® java.util.zip ããã±ã¼ã¸ãæä¾ããã¦ããã. ã®ã¬ãµã¤ãºã®ãã¡ã¤ã«ãJavaãã¼ã64Mï¼-Xms64m -Xmx64ï¼ã§åããã¦ã¿ãçµæOOMãçºçããªãã£ãã®ã§ãzipå§ç¸®å¦çã®éãªã³ã¡ã¢ã«å§ç¸®å¯¾è±¡ã®ãã¡ã¤ã«ãå
¨å±éãã¦ããªãæ§åã è¤æ°ã®ãã¡ã¤ã«ã¨ãã©ã«ããZIPã«å§ç¸®ããæ¹æ³. â è¤æ°ãã¡ã¤ã«ã®ãã¦ã³ãã¼ããè¡ãã«ã¯ãã¯ã©ã¤ã¢ã³ãå´ã«å¦çãæ»ãå¿
è¦ãããã â¡ã¯ã©ã¤ã¢ã³ãå´ã«å¦çãæ»ã代表ä¾ã¨ãã¦ajaxãåå¨ããããajaxã¯ãã¡ã¤ã«æ
å ±ãããã¹ãã¨ãã¦åå¾ãã¦ãã¾ã(ãã¤ããªã§åå¾ããå¿
è¦ãã)ã 解åå¾ã®ãã¡ã¤ã«ãµã¤ãºã¨ãã¡ã¤ã«åã«æ³¨æãã¾ããå¿
è¦ã§ããã°ãã§ãã¯ãè¡ãã¾ãã 31è¡ç®ã®ãµã¤ãºã¯1KBã¨ãã¦ãã¾ãã調æ´å¯è½ã§ãã 以ä¸ã¯ãzipãã¹ã.zipãã¡ã¤ã«ãã2ã¤ã®ãã¡ã¤ã«ãåå¾ããå³ã§ãã ã³ã³ã¹ãã©ã¯ã¿ã¨ã¡ã½ãã ã¾ã¨ããã»ã©ããªãæ°ãããã⦠è¤æ°ã®ãã¡ã¤ã«ã§ã®éçº. å§ç¸®ï¼zipå½¢å¼ï¼ãã©ã«ãã®ä½ãæ¹ããè¤æ°ã®ãã¡ã¤ã«ã1åã«ã§ãã¦å®¹éãå°ãããªããã¨ããç¹å¾´ã«ã¤ãã¦ããªã³ã©ã¤ã³ã§ã¢ã¤ã³ã³ãä½ã£ã¦ããã£ãæã®åºæ¥äºãªã©ã交ããªããã¾ã¨ãã¦ã¿ã¾ããã Javaã«ã¯æ¨æºã§zipã«å§ç¸®ã»å±éããããã®APIãããã¾ãã 確ãã«zipã«å§ç¸®ã§ããæ©è½ã¯åãã£ã¦ããã®ã§ãããæ±ãæ¹ãè¤éã§å°ãã¨ã£ã¤ãã«ããã§ãã ããã§zipå°ç¨ã®ã©ã¤ãã©ãªã§ãã Zip4j ã使ãã¾ãã åå¿è
åãã«Javaã®Fileã¯ã©ã¹ã§ãã¡ã¤ã«ãã³ãã¼ããæ¹æ³ã«ã¤ãã¦è§£èª¬ãã¦ãã¾ãããã¡ã¤ã«ã®ã³ãã¼ã«ã¯FileInputStreamã¯ã©ã¹ã¨FileOutputStreamã¯ã©ã¹ã使ç¨ãã¾ããæé ã¨æ¸ãæ¹ãè¦ãã¾ãããã java.util.zipã¨ã¯ç°ãªããzipãã¡ã¤ã«ã®ã¨ã³ã³ã¼ãã£ã³ã°ãæå®ã§ããã®ã¯truezipã§ãã å¥ã®ãµã³ãã«ãããã¾ããä»åã¯ãã¨ã³ã³ã¼ãã£ã³ã°ãæ示çã«æå®ãã¾ãã IBM437ãUTF-8ãISO-8859-1ã®ã©ã¡ããLinuxã§ã¯åä½ãã¾ããã IBM437ã¯Windowsã§åä½ãã¾ãã import java. Java ã§ã¯ããããã£ã¼ãº (Properties) ã¨ããã¯ã©ã¹ãç¨æããã¦ãã¦ããããç¨ãããã¨ã§ãã¼ã¨è¨å®å¤ã®ãã¢ã¨ããå½¢å¼ã§ãè¨å®æ
å ±ã®èªã¿è¾¼ã¿ã¨ä¿åãè¡ããã¨ãã§ãã¾ãã å°ã Properties ã¯ã©ã¹ã§ã¯ãã¼ãå¤ã String åã使ãã¾ãã èªåãªãã«èª¿ã¹ã¦,è¤æ°ã®ãã¡ã¤ã«ãzipã«åºããæ¹æ³ã¯åãã£ãã®ã§ãã, zipå
ã«ãã©ã«ããè¤æ°é層ã¤ããæ¹æ³ããããã¾ãã. ã§ã³ã¯è¤æ°ã®ã½ã¼ã¹ã³ã¼ãããä½æããã¾ãã Java ã§ã¯ãããªãã¯ã®ã¯ã©ã¹ã¯ãã¯ã©ã¹åã¨åãååã®ãã¡ã¤ã«ã«ã²ã¨ã¤å®ç¾©ã§ãã¾ãããããã£ã¦ãè¤æ°ã®ã¯ã©ã¹ãå®ç¾©ããã¨ãã«ã¯è¤æ°ã®ãã¡ã¤ã«ããæ§æããããã¨ã«ãªãã¾ãã èªåãªãã«èª¿ã¹ã¦,è¤æ°ã®ãã¡ã¤ã«ãzipã«åºããæ¹æ³ã¯åãã£ãã®ã§ãã, zipå
ã«ãã©ã«ããè¤æ°é層ã¤ããæ¹æ³ããããã¾ãã. ã¹ãã ã®ãã£ã¬ã¯ããªã«æ½åºããã¨ã³ããªåã«æå®ããæåã¨ã³ã³ã¼ãã£ã³ã°ã使ç¨ãã¾ãã Extracts all the files in the specified zip archive to a directory on the file system and uses the specified character encoding for entry names. io. åããµãã¼ããã¦ããããããã¹ã¯ã¼ãä»ãã®zipãã¡ã¤ã«ãæ±ãããæã¯æ°å°ãªãé¸æè¢ã®1ã¤ã¨ãªãã¾ãã åæ§ã«ãzip.libãããã°Zip()é¢æ°ãããã®ã ããã¨ã ã§ããããã®libã®ä¸ã«å
¥ã£ã¦ããã§ãããé¢æ°ã è¤æ°ãã¡ã¤ã«ã®å§ç¸®ã»è§£åã«å¯¾å¿ã ã¦ããªããã°æå³ããªãã®ã§ããâ¦ã è¤æ°ã®ãã©ã«ãã jarãã¡ã¤ã«ãæå®ããå ´åãWindows ã§ã¯ã»ãã³ãã³ï¼;ï¼ãUNIXç³»OSã§ã¯ã³ãã³ï¼:ï¼ã§åºåãã¾ãã ããã©ã«ãã§ã¯ã1.1 VM 㨠Java 2 SDK ã® VM ã®ä¸¡æ¹ã«äºææ§ã®ããã¯ã©ã¹ãã¡ã¤ã«ãçæãã¾ããJava 2 SDK ã® javac ããµãã¼ããããã¼ã¸ã§ã³ã¯æ¬¡ã®ã¨ããã§ãã 1.1 çæããã¯ã©ã¹ãã¡ã¤ã«ãã1.1 VM 㨠Java 2 SDK ã® VM ã«äºææ§ããããã¨ãä¿è¨¼ãã¾ãã zipFile.entriesï¼ï¼ã使ç¨ãã¦æ¢åã®ãã¡ã¤ã«å
ã®ãã¹ã¦ã®ZipEntryãªãã¸ã§ã¯ãã®åæãåå¾ããããããã«ã¼ãå¦çãã¦ããããã¹ã¦ãZipOutputStreamã«è¿½å ãã¦ãããæ°ããã¨ã³ããªã追å ãããã¨ãã§ãã¾ãã åå¿è
åãã«Javaã®Fileã¯ã©ã¹ãå©ç¨ãã¦ãã¡ã¤ã«ã移åããæ¹æ³ã«ã¤ãã¦è§£èª¬ãã¦ãã¾ããFilesã¯ã©ã¹ã¯ãã¡ã¤ã«ããã©ã«ãã«é¢ããå種æä½ãè¡ãéã«ä½¿ç¨ããã¾ããããã§ã¯moveã¡ã½ããã«ãããã¡ã¤ã«ç§»åã®æ¸ãæ¹ãè¦ã¦ããã¾ãããã ZIPæ¸åº«å
ã®ãã¡ã¤ã«ã¨ãã£ã¬ã¯ããªãåæããã«ã¯ãZipFile.OpenReadã¡ã½ããã§ZIPæ¸åº«ãéããZipArchive.Entriesããããã£ã使ç¨ãã¾ãã 次ã®ä¾ã§ã¯ããC:\test\1.zipãã«æ ¼ç´ããã¦ãããã¡ã¤ã«ã¨ãã£ã¬ã¯ããªã®æ
å ±ãåæãã¦ãã¾ãã Properties ãã¡ã¤ã«ã®èªã¿è¾¼ã¿ã¨ä¿å. java.util.zipã«ã¤ãã¦éå»ã«ããã¤ã質åããã£ãã®ã§ããã ç¥ããããã¨ããªãã£ãã®ã§è³ªåããã¦ããã ãã¾ã.