Results 1 to 3 of 3
  1. #1
    freestatedon is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default Zip Directory Structure

    Hi there -
    I'm using the java.util.zip package to create a ZIP file in a web application. The code currently looks like this (HibernateHelper.ChangeBackToForward() simply changes all backslashes to forward slashes):

    Java Code:
    try {
                String filePath = HibernateHelper.ChangeBackToForward(getServletContext().getRealPath("output.zip"));
                String path = HibernateHelper.ChangeBackToForward(getServletContext().getRealPath("/"));
                ZipOutputStream zipped = new ZipOutputStream(new FileOutputStream(filePath));
               // File file = new File(getServletContext().getRealPath("output.zip"));
    
                String[] list = new String[]{path+"photos/benioff_strain.jpg", path+"photos/gutenberg_richter.jpg"};
                byte[] buf = new byte[1024];
    
                for (int i = 0; i < list.length; i++) {
                    FileInputStream in = new FileInputStream(list[i]);
                    zipped.putNextEntry(new ZipEntry(list[i]));
    
                    int len;
                    while ((len = in.read(buf)) > 0) {
                        zipped.write(buf, 0, len);
                    }
                    zipped.closeEntry();
                    in.close();
                }
    
                zipped.close();
    
            } finally {
            }
    This works fine... to an extent. The output is a ZIP file which is readable - but it has a directory structure. i.e. when I unzip the file I get a directory structure of Users\freestatedon\...\ - my files are located at Unzip_location\Users\freestatedon\...\benioff_stra in.jpg and Unzip_location\Users\freestatedon\...\gutenberg_ri chter.jpg.

    I would much prefer it if the zip utility created NO directory structure - I would prefer my clients not to know the ins and outs of my computer. So when the client opens the ZIP file, there are simply two files, with no excess directory information. Is this possible, and how?

    Thanks.

  2. #2
    freestatedon is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    I've attached the output file (output.zip) and what I want the output to be (wanted_output.zip) to make things a bit clearer.

    Thanks.
    Attached Files Attached Files

  3. #3
    freestatedon is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    Don't worry - I sorted it.

    All that's needed is to say zipped.putNextEntry(new ZipEntry("gutenberg_richter.jpg"));

    The argument actually defines the zip file's directory structure, not the path...

    Thanks.

Similar Threads

  1. Directory Structure
    By rummy in forum New To Java
    Replies: 1
    Last Post: 01-21-2010, 12:03 PM
  2. Replies: 0
    Last Post: 03-18-2009, 01:35 PM
  3. Help with Structure
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •