|
-
Nov 13th, 2003, 06:08 PM
#1
Thread Starter
Addicted Member
File Output
I want to create and write to a zip ( or jar ) file IN CODE. How do i do this... I have a number of image files that i want an application to package into a zip/jar file for me, but i can't find any help on it. Something with the ZipOutputStream i know, but from there I'm lost... help...
To protect time is to protect everything...
-
Nov 14th, 2003, 06:04 AM
#2
Code:
File[] toWrite = new File[4];
toWrite[0] = new File("c:\\file1.txt");
toWrite[1] = new File("c:\\file2.txt");
toWrite[2] = new File("c:\\file3.txt");
toWrite[3] = new File("c:\\file4.txt");
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("c:\\target.zip"));
for(int i = 0; i < toWrite.length; ++i) {
ZipEntry entry = new ZipEntry(toWrite[i].getCanonicalPath());
entry.setMethod(ZipEntry.DEFLATED);
// You can set more fields here, like last modification time.
zos.putNextEntry(entry);
// Now open an input stream from the original file and
// copy everything over.
}
zos.close();
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|