4 Replies Latest reply: Jun 5, 2007 6:48 AM by 807606 RSS

    [b]How to get the files from a folder in a ZIP file[/b]

    807606
      Hi,

      I'm trying to get the file contained in a folder. The folder is in a ZIP file

      My folder contains 3 files and I need to get it.

      Here is my code :
      public void unzip()
           {
                try
                {
                     BufferedOutputStream out = null;
                     ZipInputStream  in = new ZipInputStream(
                                                   new BufferedInputStream(
                                                        new FileInputStream("C:\\export\\eldiv.4997.zip")));
                     ZipEntry entry;
                     while((entry = in.getNextEntry()) != null)
                     {
                          //System.out.println("Extracting: " + entry);
                          int count;
                          byte data[] = new byte[BUFFER];
      
                          // write the files to the disk
                          out = new BufferedOutputStream(
                                    new FileOutputStream("C:\\export\\"+ entry.getName()),BUFFER);
      
      
      
                          while ((count = in.read(data,0,BUFFER)) != -1)
                          {
                              if(entry.isDirectory())
                              {
      
                                  LogWriter.add("it is a directory","");
                              }
                              else
                              {
                                  out.write(data,0,count); LogWriter.add("it is a file","");
                              }
                          }
                           out.flush();
                           out.close();
                     }
                     in.close();
      
                }
                catch(Exception e)
                {
                     e.printStackTrace();
      
                }
           }