争怎路由网:是一个主要分享无线路由器安装设置经验的网站,汇总WiFi常见问题的解决方法。

Java创建Zip压缩文件

时间:2024/7/13作者:未知来源:争怎路由网人气:

import java.io.*;
import java.util.zip.*;

class Zip {
   public static void main(String args[]) throws IOException {
     byte b[] = new byte[512];
     ZipOutputStream zout = new ZipOutputStream(System.out);
     for(int i = 0; i < args.length; i ++) {
       InputStream in = new FileInputStream(args[i]);
       ZipEntry e = new ZipEntry(args[i].replace(File.separatorChar,'/'));
       zout.putNextEntry(e);
       int len=0;
       while((len=in.read(b)) != -1) {
         zout.write(b,0,len);
         }
       zout.closeEntry();
       print(e);
       }
     zout.close();
     }
     
   public static void print(ZipEntry e){
     PrintStream err = System.err;
     err.print("added " + e.getName());
     if (e.getMethod() == ZipEntry.DEFLATED) {
       long size = e.getSize();
       if (size > 0) {
         long csize = e.getCompressedSize();
         long ratio = ((size-csize)*100) / size;
         err.println(" (deflated " + ratio + "%)");
         }
       else {
         err.println(" (deflated 0%)");
         }
       }
     else {
       err.println(" (stored 0%)");
       }
     }
   }

关键词:Java创建Zip压缩文件




Copyright © 2012-2018 争怎路由网(http://www.zhengzen.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版