aspose file tools*
The moose likes Java in General and the fly likes How to unzip a file?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to unzip a file??" Watch "How to unzip a file??" New topic
Author

How to unzip a file??

Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
Hi,
can anybody tell me how to unzip a file using java codes??
i need to write a java program to unzip a file and read the file inside the zip file. if can, can give me a sample codes to look through. Thanx alot!!
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi...
Is that anything related to servlet...!!?? :roll:
Still go through java.Util.zip
There are many classes that would help you.
hth
MB
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Moving from Servlets to Java in General (Intermediate)
Dave
Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
Hi,
can show me an example of the program?? cos i hav found some prog, but there are some errors in the program, so i not very sure on how to use it.
Thanx in advance....
Shashi Kanta
Ranch Hand

Joined: May 08, 2002
Posts: 89
Hi,
Use java.util.zip.ZipInputStream for unzipping the zip file, and use ZipInputStream.getNextEntry() to get the ZipEntry object representing each file in the zip file. From the ZipEntry object you can get the name of the file inside the .zip file.
-Shashi
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
Here you go, my ZipUtil class:
ZipUtil.java
Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
Hi,
thanx, i will try and see the program. By the way, does anybody noe how to check whether the file is a zip file?? cos i need to let the user upload their files and i need to check whether the files is a zip file or not. If can, can show an example....
Thanx in advance...
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
You could take that unzip method and have it just look through the test file and see if it throws any exceptions i.e. modify it so that it doesn't write the files at all.
Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
Hi,
i try the above codes, but there is no main method. It have 1 error. May I know whether how this program runs??
Thanx in advance....

[ September 03, 2003: Message edited by: Ann Toh ]
shelly kalra
Greenhorn

Joined: Aug 19, 2003
Posts: 20
Hi Phil,
what is the purpose of using crc in your code?
Thanks,
Shelly.
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
Ann:
It is merely a utility class, you don't run it directly, you call it from your own program.
Shelly:
When making a zip file, you calculate a CRC checksum for each file and save it with the zip entry. That way when you unzip a file, you do another CRC checksum and compare it against the checksum for the zip entry, if they do not match then the file is corrupted. The unzip methods originally returned true/false depending on all checksum checks, but I changed it to return a File[] with all the valid unzipped files. I still have some thinking to do as far as error handling, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to unzip a file??