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  
Old 07-25-2007, 04:45 AM
bluesky bluesky is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 667
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
  #2  
Old 07-25-2007, 05:03 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN 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 Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Create a Cab file in C#? oxygen C# Programming 6 08-28-2009 02:12 AM
convert Excel file to CSV(or text) file using java mobilegeek Java Programming 3 02-02-2009 12:02 AM
create log files in java? saravanan Java Programming 2 08-06-2008 02:43 AM
How to create DLL file Kirubhananth ASP and ASP.NET Programming 1 04-04-2008 03:07 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 02:10 AM


All times are GMT -7. The time now is 09:35 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0