服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

利用java实现zip压缩/解压缩(2)


  zipos.putnextentry(new zipentry("zip"));
  
    ∥生成一个zip entry,写入文件输出流中,并将输出流定位于entry起始处。
  
    dataoutputstream os=new dataoutputstream(zipos);
  
    ∥用zip输出流构建dataoutputstream;
  
    os.writeutf(doc);∥将随机生成的数据写入文件中
  
    os.close();∥关闭数据流
  
    doczipsize = f.length();
  
    ∥获取压缩文件的长度
  
    showtextandinfo();∥显示数据
  
    }
  
    catch(ioexception ioe){
  
    system.out.println(ioe);
  
    }
  
    }
  
    private void showtextandinfo(){
  
    ∥显示数据文件和压缩信息
  
    textarea.replacerange(doc,0,textarea.gettext().length());
  
    infotip.settext("uncompressed size: "+doc.length()+"compressed size: "+dc zipsize);
  
    }
  
    public void actionperformed(actionevent e){
  
    string arg = e.getactioncommand();
  
    if ("new".equals(arg)) randomdata();
  
    else if ("open".equals(arg)) openfile();
  
    else if ("save".equals(arg)) savefile();
  
    else if ("exit".equals(arg)){
  
     dispose();∥关闭窗口
  
     system.exit(0);∥关闭程序
  
    }
  
    else {
  
     system.out.println("no this command!");
  
    }
  
    }
  
    }

扫描关注微信公众号