KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > util > zip > ZipOutputStream

java.util.zip
Class ZipOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.util.zip.DeflaterOutputStream
              extended by java.util.zip.ZipOutputStream
All Implemented Interfaces:
Closeable, Flushable
Direct Known Subclasses:
JarOutputStream
See Also:
Top Examples, Source Code

public static final int CENATT
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENATX
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENCOM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENCRC
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENDSK
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENEXT
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENFLG
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENHDR
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENHOW
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENLEN
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENNAM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENOFF
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final long CENSIG
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENSIZ
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENTIM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENVEM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int CENVER
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void close()
           throws IOException
See Also:
FilterOutputStream.out, FilterOutputStream.flush(), ZipException, DeflaterOutputStream, Closeable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[77]Add a file to a zipfile
By Anonymous on 2004/12/22 03:00:19  Rate
import java.io.*; 
 import java.util.zip.*; 
  
  
 public class Zip  {  
    static final int BUFFER = 2048; 
    public static void main  ( String argv [  ]  )   {  
       try  {  
          BufferedInputStream origin = null; 
          FileOutputStream dest = new  
            FileOutputStream ( "c:\\zip\\myfigs.zip" ) ; 
          ZipOutputStream out = new ZipOutputStream ( new  
            BufferedOutputStream ( dest )  ) ; 
          //out.setMethod ( ZipOutputStream.DEFLATED ) ; 
          byte data [  ]  = new byte [ BUFFER ] ; 
          // get a list of files from current directory 
          File f = new File ( "." ) ; 
          String files [  ]  = f.list (  ) ; 
  
  
          for  ( int i=0; i < files.length; i++ )   {  
             System.out.println ( "Adding: "+files [ i ]  ) ; 
             FileInputStream fi = new  
               FileInputStream ( files [ i ]  ) ; 
             origin = new  
               BufferedInputStream ( fi, BUFFER ) ; 
             ZipEntry entry = new ZipEntry ( files [ i ]  ) ; 
             out.putNextEntry ( entry ) ; 
             int count; 
             while (  ( count = origin.read ( data, 0,  
               BUFFER )  )  != -1 )   {  
                out.write ( data, 0, count ) ; 
              }  
             origin.close (  ) ; 
           }  
          out.close (  ) ; 
        }  catch ( Exception e )   {  
          e.printStackTrace (  ) ; 
        }  
     }  
  }  
  
  
 


[351]Create a zip file
By kleper { at } sysgen { dot } com { dot } br on 2004/04/15 10:36:43  Rate
String sFileName = "./associate.zip"; 
             try 
              {  
                 FileOutputStream ostream = new FileOutputStream ( sFileName ) ; 
                 ByteArrayOutputStream baos = new ByteArrayOutputStream (  ) ; 
                 ZipOutputStream zipstream = new ZipOutputStream ( new BufferedOutputStream ( ostream )  ) ; 
                  
                 Vector list = oAssociate.getAssociateList ( pp ) ; 
  
  
                 ZipEntry zipentry = new ZipEntry ( "associate.txt" ) ; 
                 zipstream.putNextEntry ( zipentry ) ; 
                 PrintStream pArq = new PrintStream ( baos ) ; 
                 String sAux = " "; 
                 for  ( int j = 0; j  <  list.size (  ) ; j++ )  
                  {  
                     Associate x =  ( Associate )  list.get ( j ) ; 
                     pArq.println ( x.toString (  )  ) ; 
                  }  
                 pArq.close (  ) ; 
                  
                 zipstream.write ( baos.toByteArray (  )  ) ; 
                 zipstream.close (  ) ; 
              }  
             catch  ( IOException exp )  
              {  
                 exp.printStackTrace (  ) ; 
              } 


public void closeEntry()
                throws IOException
See Also:
ZipException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1895]ZipOutputStream
By boopathicse { at } gmail { dot } com on 2007/06/25 01:08:35  Rate
sample coding of ZipOutputStream and ZipEntry in java.util package

public static final int DEFLATED
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int ENDCOM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int ENDHDR
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int ENDOFF
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final long ENDSIG
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int ENDSIZ
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int ENDSUB
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int ENDTOT
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int EXTCRC
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int EXTHDR
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int EXTLEN
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final long EXTSIG
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int EXTSIZ
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void finish()
            throws IOException
See Also:
ZipException, DeflaterOutputStream
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCCRC
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCEXT
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCFLG
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCHDR
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCHOW
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCLEN
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCNAM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final long LOCSIG
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCSIZ
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCTIM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int LOCVER
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void putNextEntry(ZipEntry e)
                  throws IOException
See Also:
ZipException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setComment(String comment)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1851]Comment can only be set
By Anonymous on 2006/12/07 00:13:43  Rate
Comment can be set while writing the zip file. But in ZipInputStream,  
 there is no method to get the comment, odd enough.


public void setLevel(int level)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setMethod(int method)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int STORED
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
See Also:
FilterOutputStream.write(int), ZipException, DeflaterOutputStream
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1050]Save a zip file
By DeCo on 2004/10/14 14:04:38  Rate
public void save (  String filename  )   {  
         try  {  
             // buffer do zip 
             FileOutputStream f = new FileOutputStream (  filename  ) ;             
             ZipOutputStream zout = new ZipOutputStream (  new BufferedOutputStream ( f )   ) ; 
  
  
             // buffer dos objs 
             ByteArrayOutputStream barr = new ByteArrayOutputStream (  ) ; 
             ObjectOutputStream aout = new ObjectOutputStream (  barr  ) ; 
              
             // alunos 
             zout.putNextEntry ( new ZipEntry (  "alunos.dat"  )  ) ; 
             aout.writeObject (  cadAlunos  ) ;            
             zout.write ( barr.toByteArray (  )  ) ; 
  
  
             // disciplina 
             zout.putNextEntry ( new ZipEntry ( "disciplinas.dat" )  ) ; 
             barr.reset (  ) ; 
             aout.writeObject ( cadDisciplinas ) ; 
             zout.write ( barr.toByteArray (  )  ) ; 
              
             // matricula 
             zout.putNextEntry ( new ZipEntry ( "matriculas.dat" )  ) ; 
             barr.reset (  ) ; 
             aout.writeObject ( cadMatriculas ) ; 
             zout.write ( barr.toByteArray (  )  ) ;           
              
             zout.close (  ) ;             
          }  
         catch  (  Exception e  )   {  
             e.printStackTrace (  ) ; 
          }  
          
      } 


[1685]unzip a file into folders
By richa gupta on 2005/12/08 05:26:10  Rate
how can i unzip a file into foldetr as it was zipped

public ZipOutputStream(OutputStream out)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags