Click to See Complete Forum and Search --> : File Output
Virtual24
Nov 13th, 2003, 05:08 PM
I want to create and write to a zip ( or jar ) file IN CODE. How do i do this... I have a number of image files that i want an application to package into a zip/jar file for me, but i can't find any help on it. Something with the ZipOutputStream i know, but from there I'm lost... help...
CornedBee
Nov 14th, 2003, 05:04 AM
File[] toWrite = new File[4];
toWrite[0] = new File("c:\\file1.txt");
toWrite[1] = new File("c:\\file2.txt");
toWrite[2] = new File("c:\\file3.txt");
toWrite[3] = new File("c:\\file4.txt");
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("c:\\target.zip"));
for(int i = 0; i < toWrite.length; ++i) {
ZipEntry entry = new ZipEntry(toWrite[i].getCanonicalPath());
entry.setMethod(ZipEntry.DEFLATED);
// You can set more fields here, like last modification time.
zos.putNextEntry(entry);
// Now open an input stream from the original file and
// copy everything over.
}
zos.close();
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.