Why this zip program not working for a directory.

Posted on 2012-08-13
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 35

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    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…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    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 …

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now