Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!

  • Post Reply Bookmark Topic Watch Topic
  • New Topic

unzipping files - works, but need hlp to make it better  RSS feed

Madhu Chandra
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
I am trying to unzip files using
My code works If I have a parent directory for all files/folders.
So when I unzip the structure is as -
zipFileName -> parent folder -> child files/folders
where, zipFileName and parent folder names are same.
But I want to have it as
parent folder -> child files/folders.
Here is my code :
public void unzipFiles(String zipFileName, String zipFolderPath, String unzipPath) {
Enumeration entries;
ZipFile zipFile;
try {
//Set up a directory name for the unzipped files
String courseFolderName = zipFileName.substring(0, zipFileName.indexOf("."));
//Get the zip file from its location in the "zip" folder on theServer
String separator = File.separator;
zipFile = new ZipFile(zipFolderPath + separator + zipFileName);

//Set up the directories in the data store
entries = zipFile.entries();

while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry)entries.nextElement();

if (entry.isDirectory())
String dir = entry.getName();
System.out.println("entry :"+unzipPath + separator + courseFolderName + separator + dir);
checkFilePath(unzipPath + separator + courseFolderName + separator + dir);
unzippedFolders.addElement(courseFolderName + separator + dir);


//Add the unzipped files to the data store
entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry)entries.nextElement();
if (entry.isDirectory())
if (debug)
System.out.println("Extracting file: " + entry.getName());
new BufferedOutputStream(
new FileOutputStream(unzipPath + separator + courseFolderName + separator + entry.getName())));
catch (IOException e) {
catch (Exception e) {

The above code works if the zip file is having all files under a parent folder:
zipFileName -> parent folder -> child files/folders
sample output:
unzipping the files...
entry :C:\DataStore\template\test2/IMAGES/
Creating directory C:\DataStore\template\test2/IMAGES/
entry :C:\DataStore\template\test2/INPUTS/
Creating directory C:\DataStore\template\test2/INPUTS/
otheriwse, if I have no levels under my zip level, I get an error like this:
unzipping the files...
Extracting file: schedule.htm
Extracting file: IMAGES/AMTC.GIF C:\DataStore\schedule\IMAGES/AMTC.GIF (The system
cannot find the path specified)
Can somebody pls help me find out where I am going wrong. Any help would be really really great.
[ February 12, 2003: Message edited by: Madhu Chandra ]
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!