Results 1 to 6 of 6
  1. #1
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Question How to create a zip out file from the current directory of input files

    Hi

    The code is written using the IDE eclipse.
    The errors i get are as follows :-
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The constructor ZipEntry(File) is undefined

    at Zip.Zip.main(Zip.java:33)

    Java Code:
    package Zip;
    
    import java.io.*;
    import java.util.zip.*;
    
    public class Zip {
       static final int BUFFER = 2048;
       public static void main (String argv[]) {
          try {
             BufferedInputStream origin = null;
             FileOutputStream dest = new FileOutputStream("C:\\Documents and Settings\\abc\\myzip.zip");         
             ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));            
             //out.setMethod(ZipOutputStream.DEFLATED);
             byte data[] = new byte[BUFFER];
             //get the list of files from the given path.
             File folder = new File("C:\\Documents and Settings\\abc\\Local Settings\\Temp\\ABCD\\Data");
             File[] listOfFiles = folder.listFiles();
    
             for (int i = 0; i < listOfFiles.length; i++) {                
               FileInputStream fi = new FileInputStream(listOfFiles[i]);              
                origin = new BufferedInputStream(fi, BUFFER);  
                // Add ZIP entry to output stream.
                out.putNextEntry(new ZipEntry(listOfFiles[i]));      ------------------------------------------------->This line is pointed as error .... Any help is appreciated . 
                int count;
                while((count = origin.read(data, 0,BUFFER)) != -1) {              
                   out.write(data, 0, count);
                }
                origin.close();
             }//end of for loop
             out.close();
          } catch(Exception e) {
             e.printStackTrace();
          }
       }
    }
    Thank You In Advance .
    Last edited by renu; 11-22-2010 at 08:50 PM. Reason: ran with making changes and found errors

  2. #2
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Unhappy Error :The constructor ZipEntry(File) is undefined. Pls look at the code

    Hi

    The code is written using the IDE eclipse.The purpose of this program is to create a zip file ....of all the input files
    The errors i get are as follows :-
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The constructor ZipEntry(File) is undefined

    at Zip.Zip.main(Zip.java:33)

    Java Code:
    package Zip;
    
    import java.io.*;
    import java.util.zip.*;
    
    public class Zip {
       static final int BUFFER = 2048;
       public static void main (String argv[]) {
          try {
             BufferedInputStream origin = null;
             FileOutputStream dest = new FileOutputStream("C:\\Documents and Settings\\abc\\myzip.zip");         
             ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));            
             //out.setMethod(ZipOutputStream.DEFLATED);
             byte data[] = new byte[BUFFER];
             //get the list of files from the given path.
             File folder = new File("C:\\Documents and Settings\\abc\\Local Settings\\Temp\\ABCD\\Data");
             File[] listOfFiles = folder.listFiles();
    
             for (int i = 0; i < listOfFiles.length; i++) {                
               FileInputStream fi = new FileInputStream(listOfFiles[i]);              
                origin = new BufferedInputStream(fi, BUFFER);  
                // Add ZIP entry to output stream.
                out.putNextEntry(new ZipEntry(listOfFiles[i]));      ------------------------------------------------->This line is pointed as error .... Any help is appreciated . 
                int count;
                while((count = origin.read(data, 0,BUFFER)) != -1) {              
                   out.write(data, 0, count);
                }
                origin.close();
             }//end of for loop
             out.close();
          } catch(Exception e) {
             e.printStackTrace();
          }
       }
    }
    Thank You In Advance

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default

    What constructors does ZipEntry have.
    Have you looked at the API to see?

  4. #4
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Default

    Sir

    i did see the APIs for ZipEntry

    Constructor Summary
    ZipEntry(String name)
    Creates a new zip entry with the specified name.
    ZipEntry(ZipEntry e)
    Creates a new zip entry with fields taken from the specified zip entry.


    How do i change the code ....to add the constructor and make it run.

    Pls help me solve this problem .

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default

    You're not providng it either a String or a ZipEntry are you, you're providing it a File.
    SO you need to figure out what you can use in File that makes sense to supply to the constructor.

  6. #6
    ypg
    ypg is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default

    Not very sure about the logic here, but probably go ahead with adding the filename to the ZipEntry Constructor.
    ZipEntry(listOfFiles[i].getName())

Similar Threads

  1. changing current directory
    By flaca in forum New To Java
    Replies: 7
    Last Post: 03-06-2011, 03:50 AM
  2. Create a table with buttons and the files list of a directory.
    By danielpereira in forum Advanced Java
    Replies: 1
    Last Post: 11-22-2010, 07:43 PM
  3. How to get Current Directory through File
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-05-2008, 11:14 AM
  4. How to get the current working directory in EJB?
    By sathish_2111 in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-19-2007, 05:24 PM
  5. How can i get current directory?
    By Ashley in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 02:21 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
  •