Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2009, 03:23 AM
Member
 
Join Date: Jul 2009
Posts: 4
Rep Power: 0
sito42 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-02-2009, 05:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,256
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Can you show up your code here to see?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-02-2009, 08:00 PM
Member
 
Join Date: Jul 2009
Posts: 4
Rep Power: 0
sito42 is on a distinguished road
Default
Here is my code to zip up the files:

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:

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 08:19 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-09-2009, 01:08 AM
Member
 
Join Date: Jul 2009
Posts: 4
Rep Power: 0
sito42 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
working with files (text files) itaipee New To Java 1 02-24-2009 12:38 PM
Behaving text files like binary files Farzaneh New To Java 2 08-27-2008 04:20 PM
Text and image files within jar files erhart Advanced Java 8 01-19-2008 05:43 AM
how to convert mpeg files to .wav files christina New To Java 1 08-06-2007 05:14 AM
Zipping unpacked OpenDocument in Windows fhucho Advanced Java 2 07-30-2007 05:33 PM


All times are GMT +2. The time now is 12:26 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org