tags:

views:

50

answers:

2

Hi,

My project has a few xml templates that were modified and added to a zip file. The problem was that the templates were all in a template folder but the expected format of the zip file was to have them straight in the root.

project hierarchy: templates/blah.xml

expected zip file hierarchy: blah.xml

Anyway of achieving that without moving the xml files into the root folder of the project?

Thanks

A: 

You can subclass ZipEntry and make it do whatever you want. However, you need to find out how the code is getting hold of the contents, and then modify that to get the correct resource.

Tom Hawtin - tackline
+1  A: 

I had a brain melt down... By using different names for input and output

    byte[] buf = new byte[1024];

    try
    {
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(targetFile));

        FileInputStream in = new FileInputStream("templates/blah.xml");

        out.putNextEntry(new ZipEntry("blah.xml"));

        int len;
        while ((len = in.read(buf)) > 0)
        {
            out.write(buf, 0, len);
        }

        out.closeEntry();
        in.close();
        out.close();
    } catch (IOException e)
    {
        e.printStackTrace();
    }
willcodejavaforfood
ho ahead and heckle me :)
willcodejavaforfood