wood burning stoves
The moose likes Java in General and the fly likes Java --- ZIP & UNZIP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java --- ZIP & UNZIP" Watch "Java --- ZIP & UNZIP" New topic

Java --- ZIP & UNZIP

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Can Java zip & unzip the any files(also cab files)
Susan Hoover
Ranch Hand

Joined: Jan 04, 2001
Posts: 64
It's not quite clear from your question whether you mean the classes in the java.util.jar and java.util.zip packages, or the jar tool that comes with the JDK.
Could you please elaborate?
Nitin Shivaram
Ranch Hand

Joined: Jan 17, 2001
Posts: 71
If your questions pertains to opening, reading and closing a zip file, then you could use "java.util.zip.ZipFile".

Nitin S

Nitin S<br />Sun Certified Java Programmer for the Java 2 platform.<br />Tekmetrics Certified Java Programmer For the Java 2 Platform.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1864
The following demonstrates reading from a ZIP file, listing all the files in the zip and displaying the contents of the first file in the zip. JAR file reading is similar, just with different classes and having a manifest.

source jguru.com - IO section
Rashmi Rajappa

Joined: Jul 29, 2003
Posts: 2
Try this code :

import java.io.*;
import java.util.Vector;
import java.util.zip.*;
class test
public static void ZipFile(String cfgFile) {
ZipOutputStream a_ZipOutStream = null;
File outFilename = new File(cfgFile);
int len;
// Create a zip output stream
a_ZipOutStream = new ZipOutputStream( new FileOutputStream(outFilename.getName()+".zip"));
byte[] buf = new byte[1024];
File oneFile = new File(cfgFile);
ZipEntry ze = new ZipEntry(cfgFile);
FileInputStream is = new FileInputStream(oneFile);
len = is.read(buf);
System.out.println(ze.getName() +" (" + ze.getCompressedSize()*100/ze.getSize() +"%)");
catch(IOException ioe)
if(a_ZipOutStream != null)
catch(IOException ioe)
a_ZipOutStream = null;

public static void main (String agrs[])

-Rashmi<br />Try until u succeed
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
If you want to pack and unpack what you do with WinZip with Java, you can cpmfortably do it with java.util.jar and java.util.zip packages, or with Jar.exe. As jar and zip use the sasme algorithm for compression, there will be no difference between .jar and .zip files.
I agree. Here's the link: http://aspose.com/file-tools
subject: Java --- ZIP & UNZIP
It's not a secret anymore!