This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Could you unzip a file with a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Could you unzip a file with a java program" Watch "Could you unzip a file with a java program" New topic

Could you unzip a file with a java program

bob morkos
Ranch Hand

Joined: Sep 06, 2001
Posts: 104
I have the following zip file and I want to create a program that unzips it. This is my zip file:
bob morkos
Ranch Hand

Joined: Sep 06, 2001
Posts: 104
Using, a program should use this class by unzipping to How can this be done and need a sample program that does this. Thanks.
raghavender rao
Ranch Hand

Joined: Jul 20, 2001
Posts: 45
hi ther....
hope this wil work....for unzip
public class JUNZIP {
public static void main(String[] args) {
try {

if (args.length != 1) {

System.out.println("Usage: java JUNZIP <inputfile>");

String filename = null;
if (args[0].endsWith(".gz")) {
filename = args[0].substring(0, args[0].lastIndexOf(".gz"));
} else {
System.out.println("Inputfile must have extension .gz");
FileOutputStream out = new FileOutputStream(filename);
System.out.println("Extracting archive " + args[0]);
FileInputStream file = new FileInputStream(args[0]);
GZIPInputStream in = new GZIPInputStream(file);
FileOutputStream fos = new FileOutputStream(filename);

byte[] data = new byte[2048];
int len;
while ((len = != -1) {

} catch (Exception e) {

System.out.println( "Exception is " + e.getMessage() );


for zippppppppp..........

public class JZip
public static void compress_file(String filename, String outfilename)
byte[] buf = new byte[4096]; //read buffer
int retval; //return value
//set up input stream
FileInputStream is = new FileInputStream(filename);
//set up output stream
FileOutputStream os = new FileOutputStream(outfilename);
//wrap output stream in ZipOutputStream
ZipOutputStream zos = new ZipOutputStream(os);
//set entry field in zipfile; do this once for each
//file you're compressing
zos.putNextEntry(new ZipEntry(filename));
//read the input file in and write it to the zipfile
//read file in from input stream
retval =, 0, 4096);

//-1 indicates end of file
if (retval != -1)
//write buffer to output stream
zos.write(buf, 0, retval);

}while (retval != -1);
//close this ZipEntry
//close input stream
//close output stream
catch(Exception e)
System.out.println("Exception occurred: " + e);
public static void main(String[] argv)
if (argv.length != 2)
System.out.println("usage: java jZip <filename> <zipfile name>");
compress_file (argv[0], argv[1]);

Rao<BR>Sun Certified Programmer for the Java��� 2 Platform
I agree. Here's the link:
subject: Could you unzip a file with a java program
jQuery in Action, 3rd edition