0

Looking to take an existing file(xml) and place it in a zip directory. The issue I am encountering is the directories which the xml file are currently residing in are also written to the zip as well. Does anyone have thoughts on this?

  byte[] buffer = new byte[1024];

            FileOutputStream fos = new FileOutputStream(loc + "/dir" + endFileExt+".kmz");
            ZipOutputStream zos = new ZipOutputStream(fos);

            ZipEntry ze = new ZipEntry(loc + "/dir" + endFileExt+".xml");
            zos.putNextEntry(ze);
            FileInputStream in = new FileInputStream(loc + "/dir" + endFileExt+".xml");
            int len;
            while ((len = in .read(buffer)) > 0) {
                zos.write(buffer, 0, len);
            }

            in.close();
            zos.closeEntry();
            zos.close();
user2524908
  • 861
  • 4
  • 18
  • 46
  • Take out the loc +"/dir" from the new ZipEntry() call. – Duston Jun 17 '15 at 21:39
  • How does the ZipOutputStream know where the file is for ZipEntry? I am trying to place an existing file inside of a zip directory. – user2524908 Jun 18 '15 at 01:51
  • The file comes from the FileInputStream. The parameter of the ZipEntry constructor is the path as it will appear in the zip file itself, not where the source file is located. – Duston Jun 18 '15 at 14:09

0 Answers0