CoverityFix CID:1350547,CID:1350548-Exceptional resource leaks 03/19603/3
Nimish Kapoor [Sun, 10 Dec 2017 19:10:59 +0000 (00:10 +0530)]
Change-Id: I5b372b898dbbe0eb0d5431062b3ec25ec0c77869

scilab/modules/preferences/src/java/org/scilab/modules/preferences/XCommonManager.java

index 2fafd58..ff47e7c 100644 (file)
@@ -870,17 +870,14 @@ public abstract class XCommonManager {
      * @throws FileNotFoundException
      */
     protected static void copyFile(final File in, final File out) throws IOException {
-        FileInputStream fis = new FileInputStream(in);
-        FileOutputStream fos = new FileOutputStream(out);
 
         byte[] buf = new byte[BUFSIZE];
         int i = 0;
-        try {
+        try ( FileInputStream fis = new FileInputStream(in);
+              FileOutputStream fos = new FileOutputStream(out) ) {
             while ((i = fis.read(buf)) != -1) {
                 fos.write(buf, 0, i);
             }
-            fis.close();
-            fos.close();
         } catch (IOException e) {
             e.printStackTrace();
         }