Results 1 to 2 of 2
  1. #1
    frintocf is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default The below program fails and throws an exception

    The below program fails and throws an exception "Error in opening retrieved zip file". This is only a part of program. I am very new to java. What could be the possiblities to fail and get to catch .

    public void unzip_file (String file, String dir, LiblfrEventManager manager) throws LiblfrException {
    Enumeration entries;
    ZipFile zipFile;

    try {
    zipFile = new ZipFile(file);

    entries = zipFile.entries();

    while (entries.hasMoreElements()) {
    ZipEntry entry = (ZipEntry)entries.nextElement();

    if (entry.isDirectory()) {
    // Assume directories are stored parents first then children
    //@ TODO manager.progress_notification("Extracting directory: "+entry.getName(), 0);

    (new File(entry.getName())).mkdirs();

    }
    }
    entries = zipFile.entries();

    while (entries.hasMoreElements()) {
    ZipEntry entry = (ZipEntry)entries.nextElement();

    if (!entry.isDirectory()) {
    //@ TODO manager.progress_notification("Extracting file: "+entry.getName(), 0);
    copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(dir+"/"+entry.getName())));
    }
    }

    zipFile.close();
    } catch (IOException ioe) {
    throw new LiblfrException("Error in opening retrieved zip file");
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: The below program fails and throws an exception

    Quote Originally Posted by frintocf View Post
    The below program fails and throws an exception "Error in opening retrieved zip file". This is only a part of program. I am very new to java. What could be the possiblities to fail and get to catch .
    You can find it out yourself by making the ioe object print its stacktrace (in your catch block): ioe.printStackTrace(); it tells you exactly what went wrong.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. throws exception
    By simorgh in forum New To Java
    Replies: 1
    Last Post: 07-30-2010, 12:24 AM
  2. Applet throws exception while recording
    By Basit56 in forum Java Applets
    Replies: 1
    Last Post: 08-20-2009, 01:42 PM
  3. Exception throws when I read File
    By Juggler in forum New To Java
    Replies: 11
    Last Post: 08-18-2008, 06:09 PM
  4. Main method with throws Exception
    By bugger in forum New To Java
    Replies: 3
    Last Post: 01-07-2008, 02:48 PM
  5. throws Exception
    By javaplus in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 07:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •