Friday, December 05, 2008

I just have to keep this.

 
// Zipping a file using Java

import java.io.File;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

...

File zipFile = new File("c:/myzippedfile.zip");
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry entry = new ZipEntry("mytextfile.txt");
zos.putNextEntry(entry);

// "item" here is my org.apache.commons.fileupload.FileItem
// object. replace "item.get()" with your file's byte array

zos.write(item.get());

zos.close();
 

No comments: