I am trying to zip a file using following code:
import java.io.*;
import java.util.zip.*;
public class Zip2 {
public static void zipIt(String p, String f){
byte[] buf = new byte[1024];
try {
// Create the ZIP file
String f2 = f.substring(0,f.length()-4);
String outFilename = f2+".zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
String[] filenames = new String[]{p+f};
// Compress the files
for (int i=0; i<filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames[i]);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filenames[i]));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
} catch (IOException e) {
}
}
public static void main(String args[])throws IOException {
// These are the files to include in the ZIP file
//String[] filenames = new String[]{"C:\\j2sdk1.4.2_04\\bin\\AIM_Claims_Extract_Layout.xls"};
Zip2 zipper = new Zip2();
//String path = zipper.getPath();
zipper.zipIt("E:\\Data\\ExcelFiles\\","File.xls");
// Create a buffer for reading the files
}
}
My problem is i cannot specify the destination folder. It takes bin as default to store zip file. can any body help me out
Another problem is file "File.xls" goes inside "E:\data\ExcelFiles" within the zipped file. I mean "E:\data\ExcelFiles\File.xls" is zipped instead of "File.xls"
Thanks,


