2007-12-12
Java创建ZIP压缩文件
追求简单实用的方法
// These are the files to include in the ZIP file
String[] filenames = new String[]{"filename1", "filename2"};
// Create a buffer for reading the files
byte[] buf = new byte[1024];
try {
// Create the ZIP file
String outFilename = "outfile.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
// Compress the files
for (int i=0; i<filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames[i]);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filenames[i]));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
} catch (IOException e) {
}
发表评论
最近加入圈子
最新评论
-
Tomcat6.0.18还不错
不要说admin,好像manager都不行了...
-- by zhanglubing927 -
Tomcat6.0.18还不错
不用tomcat已经好久了。公司用的是weblogic,自己也懒得折腾tomca ...
-- by tibetjungle -
Tomcat6.0.18还不错
可惜Admin部分还没有做好, 我一直用5.5的
-- by wjs0702cn -
项目管理系列一
这个不是这么算的。某一方面能够达到就很好了,其他方面不一定要达到。这只是一种统计 ...
-- by grantbb -
Tomcat6.0.18还不错
cyberblue 写道还是不怎么好用,动不动就要restart。 我这里非常 ...
-- by grantbb







评论排行榜