sample code:
import java.io.*;
import java.util.zip.*;
public class Main {
public static void main(String[] args) throws IOException {
try(FileInputStream fileInputStream = new FileInputStream("xxx.zip");
ZipInputStream zipIn = new ZipInputStream(fileInputStream)){
ZipEntry entry;
while ((entry = zipIn.getNextEntry()) != null) {
try {
if (!entry.isDirectory() && entry.getName().endsWith(".gz")) {
GZIPInputStream gzipIn = new GZIPInputStream(zipIn);
// do something
// .......
// do something
/*
* Do I need to close the GZIPInputStream?
* Closing the GZIPInputStream will cause the entire ZipInputStream to be closed.
* If it is not closed, will it lead to memory leaks?
*/
gzipIn.close();
}
} finally {
zipIn.closeEntry();
}
}
}
}
}
How to do?