Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is this exception's reason, java.io.IOException: Stream closed

Tags:

java

file

I have 2 file in a zip file I use:

while( (entry = zis.getNextEntry()) != null){
    if(entry.getName() == null ? gomrokcode != null : !entry.getName().equals(gomrokcode))
        maxversion=0;
    Scanner scanner = new Scanner(zis);
    while(scanner.hasNextLine()){
        line = scanner.nextLine();
    }
    scanner.close();
}
zis.close();

for accessing the files i get first file , and then when I return to the start of loop for second file I get this exception

    SEVERE: null
java.io.IOException: Stream closed
at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:66)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:115)

what is the reason?

like image 273
saeed arash Avatar asked Aug 12 '26 01:08

saeed arash


1 Answers

You wrap your zis stream with a Scanner, and when you close the Scanner it will close the zis stream. Hence the execption.

If you remove the scanner.close() call, I guess the iteration will proceed.

like image 72
forty-two Avatar answered Aug 13 '26 15:08

forty-two



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!