How to add a directory entry to a java.util.ZipOutputStream
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stephen_Welch
Posted On:   Wednesday, October 24, 2001 08:44 AM

How do you add an entry for a directory with no data to a ZipOutputStream?

Re: How to add a directory entry to a java.util.ZipOutputStream

Posted By:   Anonymous  
Posted On:   Friday, October 8, 2004 02:15 PM

The easiest way to zip up files and directories is to use LatteLib (www.lattelib.com), and it takes care of empty directories. For example:




new ZipFile("C:/logs.zip").compress("C:/logs/*.log");


To do the same but avoid trying to zip files that are still being writen to by another thread or process you can do the following:




new ZipFile("C:/logs.zip").compress("C:/logs/*.log",
new ReadableFileFilter());

Re: How to add a directory entry to a java.util.ZipOutputStream

Posted By:   Igor_Mikhailov  
Posted On:   Wednesday, December 19, 2001 08:33 AM


May be that helps:
import java.io.*;
import java.util.zip.*;

public class Test {
public static void main(String[] args) {
try {
FileOutputStream f = new FileOutputStream("test.zip");
ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(f));
zip.putNextEntry(new ZipEntry("xml/"));
zip.putNextEntry(new ZipEntry("xml/xml"));
zip.close();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}

About | Sitemap | Contact