Modifying a text file in a ZIP archive in Java
===

My use case requires me to open a txt file, say abc.txt which is inside a zip archive which contains key-value pairs in the form

> key1=value1

> key2=value2

.. and so on where each key-value pair is in a new line.
I have to change one value corresponding to a certain key and put the text file back in a new copy of the archive. How do I do this in java?

My attempt so far:

        ZipFile zipFile = new ZipFile("test.zip");
        final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("out.zip"));
        for(Enumeration e = zipFile.entries(); e.hasMoreElements(); ) {
            ZipEntry entryIn = (ZipEntry) e.nextElement();
            if(!entryIn.getName().equalsIgnoreCase("abc.txt")){
                zos.putNextEntry(entryIn);
                InputStream is = zipFile.getInputStream(entryIn);
                byte [] buf = new byte[1024];
                int len;
                while((len = (is.read(buf))) > 0) {            
                    zos.write(buf, 0, len);
                }
            }
            else{
                // I'm not sure what to do here
                // Tried a few things and the file gets corrupt
            }
            zos.closeEntry();
        }
        zos.close();
