• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 73984
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the exception , that ll help to solve the problem !!
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic