用java压缩文件示例(没有中文问题)

1/5/2008来源:Java教程人气:4677


  这本是别人的东西,我只是修改了中文问题。在这个基础上改一下就可以压缩多个文件和目录,甚至可以写一个WinZip之类的东东哦,有爱好的可以研究一下。
import java.io.*;
import java.util.zip.*;
  /**
   * @version Version 1.3
   */
  public class w0514{
       public static void main(String[] args){
          try{
              BufferedReader in=new BufferedReader(
                                  new InputStreamReader(new FileInputStream(args[0]),"ISO8859_1"));
              FileOutputStream f=new FileOutputStream(args[1]+".zip");
              CheckedOutputStream ch=new CheckedOutputStream(f,new CRC32());
              ZipOutputStream out=new ZipOutputStream(
                                     new BufferedOutputStream(ch));
       
             int c;
             out.putNextEntry(new ZipEntry(args[0]));
             while((c=in.read())!=-1)
                 out.write(c);
               in.close();
               out.close();
             }
          catch(Exception e){
              e.PRintStackTrace();
             }
     }
  }