Re: Package Question: java.util.zip
Re: Package Question: java.util.zip
- Subject: Re: Package Question: java.util.zip
- From: Colin Clark <email@hidden>
- Date: Wed, 6 Jul 2005 09:28:17 -0400
Hi Rick,
Here's some basic code I threw together for zipping files using the
java.io.zip package. It should be enough to get you started. The
Javadocs are helpful in clarifying how the classes work, and there
are several tutorials on the Web if you need further details.
public void zipFiles(String pathToFiles, String zipFileName)
throws FileNotFoundException, ZipException, IOException {
File directoryOfFilesToZip = new File(pathToFiles);
File[] filesToZip = directoryOfFilesToZip.listFiles();
File zipFile = new File(zipFileName);
ZipOutputStream zipFileStream = new ZipOutputStream(new
FileOutputStream(zipFile));
for (int x = 0; x < filesToZip.length; x++) {
String currentFileName = filesToZip[x].getName();
byte[] fileContents = readFileContents(filesToZip[x]);
ZipEntry currentEntry = new ZipEntry(filesToZip
[x].getName());
zipFileStream.putNextEntry(currentEntry);
zipFileStream.write(fileContents);
zipFileStream.closeEntry();
}
zipFileStream.close();
}
I hope that helps,
Colin
On 5-Jul-05, at 10:13 PM, Rick Langschultz wrote:
Does anyone have a working example with source for either a
WebObjects application, JSP, servlet or stand alone binary to
extract/encode a zip file. This is one of the features I would love
to use in one of my web applications.
Thanks,
Rick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden