diff --git a/teku/src/main/java/tech/pegasys/teku/cli/subcommand/GenesisCommand.java b/teku/src/main/java/tech/pegasys/teku/cli/subcommand/GenesisCommand.java index e2bd0ba3f31..13b05d52c72 100644 --- a/teku/src/main/java/tech/pegasys/teku/cli/subcommand/GenesisCommand.java +++ b/teku/src/main/java/tech/pegasys/teku/cli/subcommand/GenesisCommand.java @@ -60,9 +60,10 @@ public void generate( final Spec spec = networkOptions.getSpec(); final boolean outputToFile = genesisParams.outputFile != null && !genesisParams.outputFile.isBlank(); - try (final OutputStream fileStream = - outputToFile ? new FileOutputStream(genesisParams.outputFile) : System.out) { + OutputStream fileStream = System.out; + try { if (outputToFile) { + fileStream = new FileOutputStream(genesisParams.outputFile); SUB_COMMAND_LOG.generatingMockGenesis( genesisParams.validatorCount, genesisParams.genesisTime); } @@ -82,6 +83,8 @@ public void generate( if (outputToFile) { SUB_COMMAND_LOG.storingGenesis(genesisParams.outputFile, true); } + } finally { + fileStream.close(); } }