[Webinar] Streamline your web hosting managementRegister Today


Why this zip program not working for a directory.

Posted on 2012-08-13
Medium Priority
Last Modified: 2012-08-28
I have the following code where i am reading a directory and zipping it. It creates the zip file but when we unzip it gives error. The error is attached.
The directory i m specifying contains .xlsx files.
Question by:searchsanjaysharma
LVL 36

Accepted Solution

mccarl earned 2000 total points
ID: 38290885
The exception that is being thrown is telling you exactly what you need to know. However, at the moment you know nothing about the exception because you are just ignoring it. At the very least (and in a normal program you would do much more complete error handling than this), add the line e.printStackTrace(); inside the catch (IOException e) block that you have already, to see the error message that Java is trying to show you.

In this case you will work out that the String array being returned by the .list() method is just returning the bare file name and not the full path/directory names to the files. Probably easiest to just use the .listFiles() method (rather than .list() method) to return a File[]. The File object contains all the details necessary to locate each file when you are trying to zip them up.

Author Closing Comment

ID: 38344250

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question