Java/Groovy zip file create hell
===

I have tried multiple ways to create this zip file in Java/Groovy.   The first couple methods I attempted, from various blogs/postings, resulted in corrupt zip files which could not be opened.  So, I tried this one (below) which looked fairly promising. The sysouts report valid file paths being passed to the FileInputStream.  I am not sure if it is the FQ path being passed to the ZipOutputStream which is causing the problem?  Either way, below is the code, which results in small (188kb) zip file being created.

Thanks all!


    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Set;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    
    class FileZipper {
    
    	public static void makeZip(Set fullyQualifiedFileNames, String zipFileName, String outDir) throws IOException, FileNotFoundException
    	{
    		// These are the files to include in the ZIP file
    		Object[] filenames = fullyQualifiedFileNames.toArray();
    		String fileSeparator = 	(String) System.getProperties().get("file.separator");
    
    		// Create a buffer for reading the files
    		byte[] buf = new byte[1024];
    		
    	    // Create the ZIP file
    	    String outFilename = outDir + fileSeparator +zipFileName;
    	    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outFilename));
    	
    	    // Compress the files
    
    		for (Object fileName: filenames)
    		{
    			System.out.println("Adding file: " + fileName);
    	        FileInputStream fis = new FileInputStream((String)fileName);
    	
    	        // Add ZIP entry to output stream.
    	        zos.putNextEntry(new ZipEntry((String)fileName));
    	
    	        // Transfer bytes from the file to the ZIP file
    		    int len;
    			while ((len = fis.read(buf)) > 0) 
    			{
    	            zos.write(buf, 0, len);
    	        }
    		
    	        // Complete the entry
    	        zos.closeEntry();
    	        fis.close();
    		}
    	
    	    // Complete the ZIP file
    	    zos.close();
    	}
    }

