test/java/util/zip/ZipFile/CopyJar.java
Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: XXX
@@ -29,20 +29,20 @@
import java.io.*;
import java.util.zip.*;
public class CopyJar {
public static void main(String args[]) throws Exception {
- ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
- "input.jar"));
+ try (ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
+ "input.jar"))) {
ZipEntry ze = zf.getEntry("ReleaseInflater.java");
ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
InputStream in = zf.getInputStream(ze);
byte[] b = new byte[128];
int n;
zos.putNextEntry(ze);
while((n = in.read(b)) != -1) {
zos.write(b, 0, n);
}
zos.close();
- zf.close();
+ }
}
}