{"id":2124,"date":"2017-08-15T09:37:16","date_gmt":"2017-08-15T01:37:16","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=2124"},"modified":"2017-08-15T09:37:16","modified_gmt":"2017-08-15T01:37:16","slug":"%e6%96%87%e4%bb%b6%e5%8e%8b%e7%bc%a9%e5%92%8c%e8%a7%a3%e5%8e%8b","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2124","title":{"rendered":"\u6587\u4ef6\u538b\u7f29\u548c\u89e3\u538b"},"content":{"rendered":"<p>Java.util.zip \u5305\u4e2d\u63d0\u4f9b\u4e86\u53ef\u5bf9\u6587\u4ef6\u7684\u538b\u7f29\u548c\u89e3\u538b\u7f29\u8fdb\u884c\u5904\u7406\u7684\u7c7b\uff0c\u5b83\u4eec\u7ee7\u627f\u81ea\u5b57\u8282\u6d41\u7c7bOutputSteam \u548c InputStream\u3002\u5176\u4e2d GZIPOutputStream \u548c ZipOutputStream \u53ef\u5206\u522b\u628a\u6570\u636e\u538b\u7f29\u6210 GZIP \u548c Zip \u683c\u5f0f\uff0cGZIPInpputStream \u548c ZipInputStream \u53c8\u53ef\u5c06\u538b\u7f29\u7684\u6570\u636e\u8fdb\u884c\u8fd8\u539f\u3002<\/p>\n<p>\u5c06\u6587\u4ef6\u5199\u5165\u538b\u7f29\u6587\u4ef6\u7684\u4e00\u822c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>[java]1.\u751f\u6210\u548c\u6240\u8981\u751f\u6210\u7684\u538b\u7f29\u6587\u4ef6\u76f8\u5173\u8054\u7684\u538b\u7f29\u7c7b\u5bf9\u8c61\u3002\u00a0\u00a0<br \/>\n\u00a0 (\u00a0ZipOutputStream )<br \/>\n2.\u538b\u7f29\u6587\u4ef6\u901a\u5e38\u4e0d\u53ea\u5305\u542b\u4e00\u4e2a\u6587\u4ef6\uff0c\u5c06\u6bcf\u4e2a\u8981\u52a0\u5165\u7684\u6587\u4ef6\u79f0\u4e3a\u4e00\u4e2a\u538b\u7f29\u5165\u53e3\uff0c\u4f7f\u7528ZipEntry(String FileName)\u751f\u6210\u538b\u7f29\u5165\u53e3\u5bf9\u8c61\u3002<br \/>\n\u00a0 (new ZipEntry(args[i]))<br \/>\n3.\u4f7f\u7528\u00a0putNextEntry(ZipEntry entry)\u5c06\u538b\u7f29\u5165\u53e3\u52a0\u5165\u538b\u7f29\u6587\u4ef6\u3002<br \/>\n4.\u5c06\u6587\u4ef6\u5185\u5bb9\u5199\u5165\u6b64\u538b\u7f29\u6587\u4ef6\u3002<br \/>\n5.\u4f7f\u7528\u00a0closeEntry()\u7ed3\u675f\u76ee\u524d\u7684\u538b\u7f29\u5165\u53e3\uff0c\u7ee7\u7eed\u4e0b\u4e00\u4e2a\u538b\u7f29\u5165\u53e3\u3002<\/p>\n<p>\u5c06\u6587\u4ef6\u4ece\u538b\u7f29\u6587\u4ef6\u4e2d\u8bfb\u51fa\u7684\u4e00\u822c\u6b65\u9aa4\u5982\u4e0b\uff1a<br \/>\n1.\u751f\u6210\u548c\u6240\u8981\u8bfb\u5165\u7684\u538b\u7f29\u6587\u4ef6\u76f8\u5173\u8054\u7684\u538b\u7f29\u7c7b\u5bf9\u8c61\u3002<br \/>\n2.\u5229\u7528 getNextEntry()\u5f97\u5230\u4e0b\u4e00\u4e2a\u538b\u7f29\u5165\u53e3\u3002[\/java]<\/p>\n<p>\u3010\u4f8b 10-13\u3011\u8f93\u5165\u82e5\u5e72\u6587\u4ef6\u540d\uff0c\u5c06\u6240\u6709\u6587\u4ef6\u538b\u7f29\u4e3a\u201cep10_13.zip\u201d\uff0c\u518d\u4ece\u538b\u7f29\u6587\u4ef6\u4e2d\u89e3\u538b\u5e76\u663e\u793a\u3002<\/p>\n<p>[java]import java.io.*;<br \/>\nimport java.util.*;<br \/>\nimport java.util.zip.*;<br \/>\nclass ep10_13{<br \/>\n\u00a0\u00a0\u00a0 public static void main(String args[]) throws IOException{<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FileOutputStream a=new FileOutputStream(&quot;E\uff1a\\\\ep10_13.zip&quot;);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u5904\u7406\u538b\u7f29\u6587\u4ef6<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ZipOutputStream out=new ZipOutputStream(new BufferedOutputStream(a));<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for(int i=0;i&lt;args.length;i++){  \/\/\u5bf9\u547d\u4ee4\u884c\u8f93\u5165\u7684\u6bcf\u4e2a\u6587\u4ef6\u8fdb\u884c\u5904\u7406<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&quot;Writing file&quot;+args[i]);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BufferedInputStream in=new BufferedInputStream(new FileInputStream(args[i]));<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 out.putNextEntry(new ZipEntry(args[i]));  \/\/\u8bbe\u7f6e ZipEntry \u5bf9\u8c61<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int b;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while((b=in.read())!=-1)<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 out.write(b);  \/\/\u4ece\u6e90\u6587\u4ef6\u8bfb\u51fa\uff0c\u5f80\u538b\u7f29\u6587\u4ef6\u4e2d\u5199\u5165<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 in.close();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 out.close();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u89e3\u538b\u7f29\u6587\u4ef6\u5e76\u663e\u793a<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&quot;Reading file&quot;);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FileInputStream d=new FileInputStream(&quot;F:\\\\ep10_13.zip&quot;);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ZipInputStream  inout=new  ZipInputStream(new BufferedInputStream(d));<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ZipEntry z;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while((z=inout.getNextEntry())!=null){  \/\/\u83b7\u5f97\u5165\u53e3<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&quot;Reading file&quot;+z.getName());  \/\/\u663e\u793a\u6587\u4ef6\u521d\u59cb\u540d<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int x;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while((x=inout.read())!=-1)<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.write(x);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inout.close();<br \/>\n\u00a0\u00a0\u00a0 }<br \/>\n}[\/java]<\/p>\n<p>\u4f8b 10-13 \u8fd0\u884c\u540e\uff0c\u5728\u7a0b\u5e8f\u76ee\u5f55\u5efa\u7acb\u4e00\u4e2a ep10_13.zip \u7684\u538b\u7f29\u6587\u4ef6\uff0c\u4f7f\u7528\u89e3\u538b\u7f29\u8f6f\u4ef6\uff08\u5982 WinRAR\u7b49\uff09\uff0c\u53ef\u4ee5\u5c06\u5176\u6253\u5f00\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java.util.zip \u5305\u4e2d\u63d0\u4f9b\u4e86\u53ef\u5bf9\u6587\u4ef6\u7684\u538b\u7f29\u548c\u89e3\u538b\u7f29\u8fdb\u884c\u5904\u7406\u7684\u7c7b\uff0c\u5b83\u4eec\u7ee7\u627f\u81ea\u5b57\u8282\u6d41\u7c7bOutputSte [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2124"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2124"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2124\/revisions"}],"predecessor-version":[{"id":2126,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2124\/revisions\/2126"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}