test/java/util/zip/ZipFile/GetDirEntry.java

Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: alanb, dholmes, sherman

@@ -30,14 +30,14 @@
 import java.io.*;
 import java.util.zip.*;
 
 public class GetDirEntry {
     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("META-INF");
         if (ze == null) {
             throw new Exception("failed to find a directory entry");
         }
-        zf.close();
+        }
     }
 }