Results 1 to 4 of 4
  1. #1
    sito42 is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default Issues with zipping files

    Hi there,

    I was wondering if someone can shed some light as to why zipping files with the java.util.zip package does not work the same as Winzip. I use this auto-generated zip file to upload to my webserver. When uploading, it unzips the file, and reads an xml file. The xml file only contains one opening and closing tag but somehow the system hiccups when trying to read this xml file. It's as if the java.util.zip added extra hidden characters to the zip file. When I use Winzip to manually zip it up, it uploads just fine. Does it have anything to do with the different compression levels between the two utiliites?

    Any help would be much appreciated.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    sito42 is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default

    Here is my code to zip up the files:

    Java Code:
    public void createZipFile(String[] source, String zipFileName) {
    		
    	byte[] buf = new byte[18024];
        	
        	try {
                ZipOutputStream out = new ZipOutputStream(new  FileOutputStream(zipFileName));
            
                for (int i=0; i<source.length; i++) {
                   FileInputStream in = new FileInputStream(source[i]);
            
                    out.putNextEntry(new ZipEntry(source[i]));
            
                    int len;
                    while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                    }
                    out.closeEntry();
                   in.close();
                }        
                 out.close();
           } catch (Exception e) {
                 e.printStackTrace();
            }
    }
    and this is the code I use to read the xml in the zip file:

    Java Code:
    File propertyFile = new File (propertyFilePath);
            FileInputStream fis = null;
            try {
            	fis = new FileInputStream(propertyFile);
            }
            catch (IOException e){
            	System.out.println("Problem reading properties.xml: " + e);
            }
    It throws an exception when I tried to read the xml file, a file that contains only a opening and closing tag. It says "de.schlichtherle.io.UpdatingArchiveController$Arc hiveEntryNotFoundException: C:\\temp\test.zipCategory/properties.xml: No such entry!". I printed out the absolute path to it and it was valid (C:\temp\test.zip\Category\properties.xml). I'm not sure what the problem is. Works fine when I use winzip to manually zip up these files.

    Thanks!
    Last edited by sito42; 07-02-2009 at 07:19 PM.

  4. #4
    sito42 is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default

    I figured it out. It seemed like truezip didn't like the fact that the zip file was created using ZipOutputStream. So when I used truezip to zip the file, it worked.

Similar Threads

  1. working with files (text files)
    By itaipee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 11:38 AM
  2. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  3. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 04:43 AM
  4. how to convert mpeg files to .wav files
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:14 AM
  5. Zipping unpacked OpenDocument in Windows
    By fhucho in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2007, 04:33 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
  •