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!");
}
}
}
闽公网安备 35060202000074号