IT Community - Software Programming, Web Development and Technical Support

How to create a ZIP File in Java?

This is a discussion on How to create a ZIP File in Java? within the Java Programming forums, part of the Software Development category; How to create a ZIP File in Java?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-25-2007, 05:45 AM
bluesky bluesky is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 201
bluesky is on a distinguished road
Question How to create a ZIP File in Java?

How to create a ZIP File in Java?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-25-2007, 06:03 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to create a ZIP File in Java?

// these are the files to include in the ZIP file

String[] source = new String[]{"source1", "source2"};

// Create a buffer for reading the files
byte[] buf = new byte[1024];

try {
// Create the ZIP file
String target = "target.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target));

// Compress the files
for (int i=0; i<source.length; i++) {
FileInputStream in = new FileInputStream(source[i]);

// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(source[i]));

// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}

out.closeEntry();
in.close();
}

// Complete the ZIP file
out.close();
} catch (IOException e) {
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
create log files in java? saravanan Java Programming 2 08-06-2008 03:43 AM
How to create a Setup file in VS 2005 to start a installer from a installer file? $enthil C# Programming 2 11-16-2007 03:10 AM
How to Create a Cab file in C#? oxygen C# Programming 5 10-25-2007 01:13 AM
convert Excel file to CSV(or text) file using java mobilegeek Java Programming 2 09-06-2007 06:42 AM
Is it possible to create an .ini file for CEAppMgr that will disable.. theone Mobile Software Development 1 07-19-2007 01:00 AM


All times are GMT -7. The time now is 08:03 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0