test/java/io/File/SetLastModified.java

Print this page
rev 3565 : 7022624: use try-with-resources in java.io tests
Reviewed-by: XXX

@@ -103,13 +103,13 @@
         final long G = 1024L * 1024L * 1024L;
         final long MAX_POSITION =
             System.getProperty("os.name").startsWith("Windows") ? 0L : 3L*G;
         long pos = 0L;
         while (pos <= MAX_POSITION) {
-            FileChannel fc = new FileOutputStream(f).getChannel();
+            try (FileChannel fc = new FileOutputStream(f).getChannel()) {
             fc.position(pos).write(ByteBuffer.wrap("x".getBytes()));
-            fc.close();
+            }
             ot = f.lastModified();
             System.out.format("check with file size: %d\n", f.length());
             if (!f.setLastModified(nt))
                 throw new Exception("setLastModified failed on file: " + f);
             ck(f, nt, f.lastModified());