Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Receiving multiple XML-files from within a ZIP-file

807589Oct 26 2008 — edited Oct 27 2008
Hello,

I'm trying to store data of my program in several XML files, which are than again compressed into one ZIP file. I have no problem when saving/receiving a single zipped XML file. But when I iterate the ZIP-file to receive more than XML file, I get an error message and I simply can't find the mistake. Here's the code I use, were "fp" is the filepath to the ZIP file:
            try { 
                ZipInputStream zip = new ZipInputStream(new FileInputStream(fp)); 
                ZipEntry entry; 
                
                while ((entry=zip.getNextEntry())!=null) { 
                    String entryname = entry.getName(); 

                    if (entryname.equals("zknFile.xml") || 
                        entryname.equals("authorFile.xml") || 
                        entryname.equals("keywordFile.xml")) { 
                        try { 
                            SAXBuilder builder = new SAXBuilder(); 
                            Document doc = new Document(); 
                            doc = builder.build(zip); 

                            if (entryname.equals("zknFile.xml")) dataObj.setZknData(doc); 
                            if (entryname.equals("authorFile.xml")) dataObj.setAuthorData(doc); 
                            if (entryname.equals("keywordFile.xml")) dataObj.setKeywordData(doc); 
                        } 
                        catch (JDOMException e) { 
                            System.out.println("Fehler bei SaxBuilder"); 
                            e.printStackTrace(); 
                            Logger.getLogger(CLoadDialog.class.getName()).log(Level.SEVERE, null, e); 
                        } 
                    } 
                } 
                zip.close(); 
            } 
            catch (IOException e) { 
                System.out.println("Fehler bei NextEnry"); 
                e.printStackTrace(); 
                Logger.getLogger(CLoadDialog.class.getName()).log(Level.SEVERE, null, e); 
            }        
I tried to debug this code, and it seems like the error occurs, when the while-loop is iterated for the second time. This is the error message I receive:
Fehler bei NextEnry 
java.io.IOException: Stream closed 
at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:44) 
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:68) 
at zettelkasten.CLoadDialog$LoadFileTask.doInBackground(CLoadDialog.java:313) 
at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source) 
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 
at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
at org.jdesktop.swingworker.SwingWorker.run(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) 
at java.lang.Thread.run(Thread.java:637)
When I just have one XML file and don't use the while-loop, everything works well. I also retrieve the XML file with "zip.getNextEntry())". Now I just put a while-loop "around" this statement, and it doesn't work...

I'm using NetBeans 6.1 under Mac OS X 10.5.5., JDK 6 and the JDOM-API 1.1
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2008
Added on Oct 26 2008
6 comments
548 views