diff --git a/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java b/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java index 215b09e1a..c02f7088a 100644 --- a/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java +++ b/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java @@ -327,14 +327,18 @@ public class BinaryExporter implements JmeExporter { public boolean save(Savable object, File f) throws IOException { File parentDirectory = f.getParentFile(); - if(parentDirectory != null && !parentDirectory.exists()) { + if (parentDirectory != null && !parentDirectory.exists()) { parentDirectory.mkdirs(); } FileOutputStream fos = new FileOutputStream(f); - boolean rVal = save(object, fos); - fos.close(); - return rVal; + try { + return save(object, fos); + } finally { + if (fos != null) { + fos.close(); + } + } } public BinaryOutputCapsule getCapsule(Savable object) { diff --git a/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java b/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java index 47ea18e6b..933bee721 100644 --- a/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java +++ b/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java @@ -267,9 +267,13 @@ public final class BinaryImporter implements JmeImporter { public Savable load(File f, ReadListener listener) throws IOException { FileInputStream fis = new FileInputStream(f); - Savable rVal = load(fis, listener); - fis.close(); - return rVal; + try { + return load(fis, listener); + } finally { + if (fis != null) { + fis.close(); + } + } } public Savable load(byte[] data) throws IOException {