怎样从一个文件中读出内容,再写到zip压缩?

bitterghost 2003-12-31 11:16:49
怎样从一个文件中读出内容,再写到zip压缩?
...全文
121 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
knight0526 2004-01-08
  • 打赏
  • 举报
回复
让我们共同关注这个问题吧!
kenli 2004-01-08
  • 打赏
  • 举报
回复
用ZipOutputStream
Tiack 2004-01-08
  • 打赏
  • 举报
回复
不对啊,zip的文件没错,可是在解压时就不对了,将同目录下的所有文件放出来,晕.
stonecsdn 2004-01-08
  • 打赏
  • 举报
回复
看到过读jar的程序,读zip的学习。
icebound1 2004-01-08
  • 打赏
  • 举报
回复
mark
fangrong 2004-01-08
  • 打赏
  • 举报
回复
我就知道用java.util.zip包

呵呵

学习ing
rongrongGsr 2004-01-07
  • 打赏
  • 举报
回复
关注一下
zkjbeyond 2004-01-07
  • 打赏
  • 举报
回复
下班了。明天给你写个。

java.util.zip.*;

其实重文件中读出 StringBuffer

压缩成 byte[]

allways 2004-01-07
  • 打赏
  • 举报
回复
转:

package com.jcc.tijtest.chap122;

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

/**
* @author JCC
*
* ¸ü¸ÄËùÉú³ÉÀàÐÍ×¢Ê͵ÄÄ£°åΪ
* ´°¿Ú > Ê×Ñ¡Ïî > Java > ´úÂëÉú³É > ´úÂëºÍ×¢ÊÍ
*/
public class ZipCompress {

public static void main(String[] args)
throws Exception{
String FileName ="d:\\testPkg.zip" ;
String FileName1 ="d:\\test1.txt" ;
String FileName2 ="d:\\test2.txt" ;
FileOutputStream f = new FileOutputStream(FileName) ;
CheckedOutputStream csum = new CheckedOutputStream(f , new Adler32()) ;
ZipOutputStream zos = new ZipOutputStream(csum) ;
BufferedOutputStream out = new BufferedOutputStream(zos) ;

zos.setComment("zos.setcommment") ;

{

BufferedReader in = new BufferedReader(new FileReader(FileName1)) ;
zos.putNextEntry(new ZipEntry("test1.txt")) ;
int c ;
while((c=in.read())!=-1)
out.write(c) ;
in.close() ;

}

//out.close() ;
{
//the second file
BufferedReader in2 = new BufferedReader(new FileReader(FileName2)) ;
zos.putNextEntry(new ZipEntry("test2.txt")) ;
int c ;
while((c=in2.read())!=-1)
out.write(c) ;
in2.close() ;

}
out.close() ;
System.out.println("checksum:"+csum.getChecksum().getValue()) ;

FileInputStream fi = new FileInputStream("d:\\testpkg.zip") ;
CheckedInputStream csumi = new CheckedInputStream(fi , new Adler32()) ;
ZipInputStream in2 = new ZipInputStream(csumi) ;
BufferedInputStream bis = new BufferedInputStream(in2) ;
ZipEntry ze ;
while((ze = in2.getNextEntry())!=null){
System.out.println(ze) ;
int x ;
while((x=bis.read())!=-1){
System.out.println((char)x) ;
}
}

}

}
whyxx 2004-01-07
  • 打赏
  • 举报
回复
什么叫文件中读出内容,压到zip中去,zip中只能圧文件,还没听说过可以圧文件里的内容的.
lijintaowangyanqiu 2004-01-07
  • 打赏
  • 举报
回复
study
bitterghost 2004-01-05
  • 打赏
  • 举报
回复
没人知道么
mymoto 2003-12-31
  • 打赏
  • 举报
回复
不会,学习来,mark
bitterghost 2003-12-31
  • 打赏
  • 举报
回复
up

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧