src/solaris/classes/java/util/prefs/FileSystemPreferences.java

Print this page
rev 3509 : 7021209: convert lang, math, util to use try-with-resources
Reviewed-by: XXX

@@ -569,13 +569,13 @@
                 public Void run() throws BackingStoreException {
                     Map<String, String> m = new TreeMap<>();
                     long newLastSyncTime = 0;
                     try {
                         newLastSyncTime = prefsFile.lastModified();
-                        FileInputStream fis = new FileInputStream(prefsFile);
+                        try (FileInputStream fis = new FileInputStream(prefsFile)) {
                         XmlSupport.importMap(fis, m);
-                        fis.close();
+                        }
                     } catch(Exception e) {
                         if (e instanceof InvalidPreferencesFormatException) {
                             getLogger().warning("Invalid preferences format in "
                                                         +  prefsFile.getPath());
                             prefsFile.renameTo( new File(

@@ -616,13 +616,13 @@
                 public Void run() throws BackingStoreException {
                     try {
                         if (!dir.exists() && !dir.mkdirs())
                             throw new BackingStoreException(dir +
                                                              " create failed.");
-                        FileOutputStream fos = new FileOutputStream(tmpFile);
+                        try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
                         XmlSupport.exportMap(fos, prefsCache);
-                        fos.close();
+                        }
                         if (!tmpFile.renameTo(prefsFile))
                             throw new BackingStoreException("Can't rename " +
                             tmpFile + " to " + prefsFile);
                     } catch(Exception e) {
                         if (e instanceof BackingStoreException)