CID 1350568 fixed using Java try-with-ressource 04/18904/2
Clément DAVID [Wed, 18 Jan 2017 10:53:45 +0000 (11:53 +0100)]
Change-Id: Ic579ae6a9dd043343beb0e724386dfb8c25f5a25

scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/Modelica.java

index a2dc1d0..09a84f4 100644 (file)
@@ -19,7 +19,7 @@ package org.scilab.modules.xcos.modelica;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.StringWriter;
@@ -168,10 +168,10 @@ public final class Modelica {
             }
             buffer.append(newline);
 
-            new FileOutputStream(file).write(strw.toString().getBytes());
-        } catch (FactoryConfigurationError e) {
-            Logger.getLogger(Modelica.class.getName()).severe(e.toString());
-        } catch (IOException e) {
+            try (FileWriter fw = new FileWriter(file)) {
+                fw.append(buffer);
+            }
+        } catch (FactoryConfigurationError | IOException e) {
             Logger.getLogger(Modelica.class.getName()).severe(e.toString());
         }
     }