Hi, with the command line program "zip" I can create a zip-File with annotated folders inside. I try to generate such a zip-File with the org.apache.tools.zip classes coming with ant.jar.
Here is my small example program:
package org.example.zip;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
public class ZipTest {
public static void main (String argv[]) {
try {
FileOutputStream dest = new
FileOutputStream("/tmp/checkFolder.zip");
ZipOutputStream out = new ZipOutputStream(new
BufferedOutputStream(dest));
ZipEntry folderEntry = new ZipEntry("TestFolder");
folderEntry.setComment("My Folder comment.");
out.putNextEntry(folderEntry);
out.closeEntry();
ZipEntry fileEntry = new
ZipEntry("TestFolder/TestFile.txt");
fileEntry.setComment("My File comment.");
out.putNextEntry(fileEntry);
out.write("Hallo Zip!".getBytes());
out.closeEntry();
out.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
On a first look with unzip everything looks nice:
Archive: /tmp/checkFolder.zip
Length Date Time Name
-------- ---- ---- ----
0 09-22-09 15:09 TestFolder
My Folder comment.
10 09-22-09 15:09 TestFolder/TestFile.txt
My File comment.
-------- -------
10 2 files
But the build in windows Zip always finds an empty file with the name of the
folder and unzip has a problem to extract it:
unzip /tmp/checkFolder.zip
Archive: /tmp/checkFolder.zip
inflating: TestFolder
checkdir error: TestFolder exists but is not directory
unable to process TestFolder/TestFile.txt.
Is there a way to tell a ZipEntry that it is folder?
How can I write a commented folder to a zip file?
Yours
Arne
smime.p7s
Description: S/MIME cryptographic signature
