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)
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 .
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)
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