File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ong CherYee
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2906
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the exception , that ll help to solve the problem !!
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 341
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic