• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to unzip a file??

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
Is that anything related to servlet...!!?? :roll:
Still go through java.Util.zip
There are many classes that would help you.
hth
MB
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving from Servlets to Java in General (Intermediate)
Dave
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here you go, my ZipUtil class:
ZipUtil.java
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Phil,
what is the purpose of using crc in your code?
Thanks,
Shelly.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic