GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes I cant figure out why this zipping code produces an exception  :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I cant figure out why this zipping code produces an exception  :(" Watch "I cant figure out why this zipping code produces an exception  :(" New topic
Author

I cant figure out why this zipping code produces an exception :(

Ong CherYee
Greenhorn

Joined: Jan 17, 2008
Posts: 11
I have a method which performs zipping. I took the zipping code found on the net and modified it to make sure that folders can be zipped as well.

When using the code to zip a folder, it always produces an exception. Yet, the strange thing is that the code still manages to zip the folder correctly. I can view the contents of the zipped folder and unzip it.

There is no such problem if the zipping is done on a file.

The code is shown below:



I guess it is the code within the elseif(file.isDirectory()) clause which cause the exception but I cant figure out which line is the culprit, especially when the folder still manages to be zipped correctly.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39097
    
  23
Don't know anything about that, but I would suggest you change your catch to include

e.printStackTrace();
System.err.println(e.getMessage());

That way you will gain useful additional information about the Exception.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Please post the exception , that ll help to solve the problem !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

Probably the error is in the function

Well, there is no source code for that so can't actualy comment. Please post the exception and if required the code so that we can help.
Ong CherYee
Greenhorn

Joined: Jan 17, 2008
Posts: 11
I've printed out the exception message and it says that the Zip file must have at least one entry.



However, the folder which was zipped has got 4 files inside. What could be causing the problem?
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

at zipAndSign.myUtils.Zip.FileZip.SourcingPerformZip(FileZip.java:407


I mentioned that the error is in the SourcingPerformZip function. As the source code for that is missing so can't comment perfectly about error.
But, the error is that in this function when you get hold of a folder you are iterating foreach file. Now once the zip is being made all the files that were zipped are not getting binded to the zip created. Thus there occurs a blank zip with no files in it.

Just try to modify your code and add the zipped files to zip over the iteration. I think that should solve the problem.

Otherwise the code is attaching the files without zipping them so that can also be problematic.

Whatever the case you are doing something wrong with ZipEntry

Hope that helps.
[ April 03, 2008: Message edited by: Anubhav Anand ]
 
GeeCON Prague 2014
 
subject: I cant figure out why this zipping code produces an exception :(