Results 1 to 1 of 1
  1. #1
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Question unzip.waitfor();?

    I'm trying to figure out how to get my main class to wait while the above code is executed. For processes I've always used process.waitfor(); but that wont work.

    This is the code I'm using

    Java Code:
    public class runUnZip {
    
        public static void runUnZip(String command, String curDir) throws IOException {
      
            try {
                ZipFile zf = new ZipFile(command);
                Enumeration<? extends ZipEntry> zipEnum = zf.entries();
                String dir = curDir;
               
                while (zipEnum.hasMoreElements()) {
                    ZipEntry item = (ZipEntry) zipEnum.nextElement();
    
                    if (item.isDirectory()) {
                        File newdir = new File(dir + File.separator + item.getName());
                        newdir.mkdir();
                    } else {
                        String newfilePath = dir + File.separator + item.getName();
                        File newFile = new File(newfilePath);
                        if (!newFile.getParentFile().exists()) {
                            newFile.getParentFile().mkdirs();
                        }
    
                        InputStream is = zf.getInputStream(item);
                        FileOutputStream fos = new FileOutputStream(newfilePath);
                        int ch;
                        while ((ch = is.read()) != -1) {
                            fos.write(ch);
                        }
                        is.close();
                        fos.close();
                    }
                }
                zf.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    And this is the code I'm using to execute with

    Java Code:
                try {
                    String command = curDir + "lib" + fs + "dbbackup.zip";
                    System.out.println(command);
                    File nn = new File(curDir);
                    runUnZip.runUnZip(command, curDir);
    
                } catch (IOException ex) {
                }
            } catch (IOException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
    I'm trying to figure out how to get my main class to wait while the above code is executed. For processes I've always used process.waitfor(); but that wont work.
    Last edited by IYIaster; 04-17-2010 at 06:33 AM.

Similar Threads

  1. Process.waitFor() method hangs application.
    By simmi in forum New To Java
    Replies: 2
    Last Post: 02-10-2010, 03:35 AM
  2. Unzip
    By msankar.ravi in forum New To Java
    Replies: 1
    Last Post: 11-30-2009, 10:32 AM
  3. Replies: 2
    Last Post: 10-01-2009, 11:02 AM
  4. UnZip
    By hello_swe in forum New To Java
    Replies: 3
    Last Post: 02-17-2008, 10:58 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
  •