Results 1 to 6 of 6
- 11-22-2010, 05:08 PM #1
Senior Member
- Join Date
- May 2010
- Posts
- 113
- Rep Power
- 0
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)
Thank You In Advance .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(); } } }Last edited by renu; 11-22-2010 at 07:50 PM. Reason: ran with making changes and found errors
- 11-22-2010, 09:28 PM #2
Senior Member
- Join Date
- May 2010
- Posts
- 113
- Rep Power
- 0
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)
Thank You In AdvanceJava 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(); } } }
- 11-23-2010, 08:43 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
What constructors does ZipEntry have.
Have you looked at the API to see?
- 11-23-2010, 06:29 PM #4
Senior Member
- Join Date
- May 2010
- Posts
- 113
- Rep Power
- 0
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 .
- 11-24-2010, 08:45 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
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.
- 11-24-2010, 10:57 AM #6
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
changing current directory
By flaca in forum New To JavaReplies: 7Last Post: 03-06-2011, 02:50 AM -
Create a table with buttons and the files list of a directory.
By danielpereira in forum Advanced JavaReplies: 1Last Post: 11-22-2010, 06:43 PM -
How to get Current Directory through File
By Java Tip in forum java.ioReplies: 0Last Post: 04-05-2008, 10:14 AM -
How to get the current working directory in EJB?
By sathish_2111 in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-19-2007, 04:24 PM -
How can i get current directory?
By Ashley in forum New To JavaReplies: 1Last Post: 05-26-2007, 01:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks