posts - 22,comments - 35,trackbacks - 0
 1 import  java.util.zip.ZipOutputStream;
 2 import  java.io.IOException;
 3 import  java.util.zip.ZipEntry;
 4 import  java.io.FileOutputStream;
 5 import  java.io.FileInputStream;
 6
 7 class  CSVZip  {
 8
 9    public   static   void  Zip(String file,String zipfile)  {
10      try   {
11        // 创建文件输入流对象
12       FileInputStream in  =   new  FileInputStream(file);  // 0
13        // 创建文件输出流对象
14       FileOutputStream out  =   new  FileOutputStream(zipfile);  // 1
15        // 创建ZIP数据输出流对象
16       ZipOutputStream zipOut  =   new  ZipOutputStream(out);
17        // 创建指向压缩原始文件的入口
18       ZipEntry entry  =   new  ZipEntry(file);  // 0
19       zipOut.putNextEntry(entry);
20        // 向压缩文件中输出数据
21        int  nNumber;
22        byte [] buffer  =   new   byte [ 512 ];
23        while  ( (nNumber  =  in.read(buffer))  !=   - 1 )
24         zipOut.write(buffer,  0 , nNumber);
25        // 关闭创建的流对象
26       zipOut.close();
27
28       out.close();
29       in.close();
30
31     }
catch  (IOException e)  {
32                System.out.println(e);
33                            }

34
35   }

36 }

37
posted on 2006-06-05 17:06 kelven 阅读(794) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: