🔒 Closed Creating zipfile using zipoutputstream

Status
Not open for further replies.

Eyaa-

Honorary Poster
This Java example shows how create zip file containing one file using Java ZipOutputStream class.
import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.zip.ZipEntry;

import java.util.zip.ZipException;

import java.util.zip.ZipOutputStream;



public class CreateZipFile {
public static void main(String args[])
{
{
String zipFile = "C:/FileIO/zipdemo.zip";
String sourceFile = "C:/FileIO/sourcefile.doc";
byte[] buffer = new byte[1024];
FileOutputStream fout = new FileOutputStream(zipFile);
ZipOutputStream zout = new ZipOutputStream(fout);
FileInputStream fin = new FileInputStream(sourceFile);
zout.putNextEntry(new ZipEntry(sourceFile));
int length;
while((length = fin.read(buffer)) > 0)
{
zout.write(buffer, 0, length);
}
zout.closeEntry();
fin.close();
zout.close();
System.out.println("Zip file has been created!");

}

catch(IOException ioe)
{
System.out.println("IOException :" + ioe);
}
}
}
kung may gusto kayo I pwede nyo gamitin tong codes na to use zip files
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 515
    Views
  • 2
    Participants
Last reply from:
t h i n k s t e r

Trending Topics

Online now

Members online
988
Guests online
1,164
Total visitors
2,152

Forum statistics

Threads
2,273,843
Posts
28,952,037
Members
1,234,978
Latest member
panda1829
Back
Top