Hi All,
I have some files(.xml files) to be placed inside a zip file. I tried below code, where instead of placing (.xml)files inside the zip files, its removing all the existing files from zip file and not inserting the (.xml) files. Please let me know if i am missing something
try {
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream("c:\\zip\\myfigs.zip");
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
dest));
out.setMethod(ZipOutputStream.DEFLATED);
byte data[] = new byte[BUFFER];
// get a list of files from current directory
// File f = new File(".");
File f = new File("C:\\outputFile");
String files[] = f.list();
for (int i = 0; i < files.length; i++) {
System.out.println("Adding: " + files[i]);
FileInputStream fi = new FileInputStream(f.getAbsoluteFile()
+ "\\" + files[i]);
origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(f.getAbsoluteFile() + "\\"
+ files[i]);
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Thanks,
Chinnu