diff --git a/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java b/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java index 1700d68b..364560d7 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java @@ -127,9 +127,10 @@ public class FileWalletExportPane extends TitledDescriptionPane { private void exportWallet(File file, Wallet exportWallet) { try { if(file != null) { - OutputStream outputStream = new FileOutputStream(file); - exporter.exportWallet(exportWallet, outputStream); - EventManager.get().post(new WalletExportEvent(exportWallet)); + try(OutputStream outputStream = new FileOutputStream(file)) { + exporter.exportWallet(exportWallet, outputStream); + EventManager.get().post(new WalletExportEvent(exportWallet)); + } } else { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); exporter.exportWallet(exportWallet, outputStream); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java b/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java index 6d425b1a..b993dba4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java @@ -202,7 +202,6 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle } writer.flush(); - writer.close(); } catch(Exception e) { log.error("Error exporting Coldcard multisig wallet", e); throw new ExportException("Error exporting Coldcard multisig wallet", e); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java b/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java index 10004f22..1110abc8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java @@ -367,7 +367,6 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport String json = gson.toJson(eJson); outputStream.write(json.getBytes(StandardCharsets.UTF_8)); outputStream.flush(); - outputStream.close(); } catch (Exception e) { log.error("Error exporting Electrum Wallet", e); throw new ExportException("Error exporting Electrum Wallet", e); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java index ce7576ae..84ec0e59 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java @@ -28,7 +28,6 @@ public class Sparrow implements WalletExport { Storage storage = AppServices.get().getOpenWallets().get(wallet); Files.copy(storage.getWalletFile().toPath(), outputStream); outputStream.flush(); - outputStream.close(); } catch(Exception e) { log.error("Error exporting Sparrow wallet file", e); throw new ExportException("Error exporting Sparrow wallet file", e); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java b/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java index 6d83ae55..76032800 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java @@ -31,7 +31,6 @@ public class SpecterDesktop implements WalletImport, WalletExport { String json = gson.toJson(specterWallet); outputStream.write(json.getBytes(StandardCharsets.UTF_8)); outputStream.flush(); - outputStream.close(); } catch(Exception e) { log.error("Error exporting Specter Desktop wallet", e); throw new ExportException("Error exporting Specter Desktop wallet", e);