|
This sample code shows the method to create a Zip file and add files to it. It uses ZipOutputStream to write zip file.
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipFileWrtExp {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("C:\\MyZip.zip");
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry ze= new ZipEntry("C:\\file1.txt");
zos.putNextEntry(ze);
zos.closeEntry();
ze= new ZipEntry("C:\\file2.txt");
zos.putNextEntry(ze);
zos.closeEntry();
zos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.