-1

Does this try-catch-with-resources auto-close? It has a return in the body before it reaches the end. Will it still auto-close the stream?

    try (FileReader reader = new FileReader(characterFile)) {
        final SavedPlayer savedPlayer = GSON.fromJson(reader, SavedPlayer.class);

        return new Login(player, LoginType.SUCCESSFUL);
    } catch (IOException e) {
        e.printStackTrace();
        return new Login(player, LoginType.INPUT_FAILURE);
    }
user2997204
  • 1,344
  • 2
  • 12
  • 24
  • 2
    AFAKI `try-with-resources` is somewhat like `try-finally`, where the close operation is guaranteed to always be executed – MadProgrammer Sep 12 '15 at 01:30

1 Answers1

0

Yes.

The try-with-resources Statement (Java Tutorials) reads (in part)

The try-with-resources statement ensures that each resource is closed at the end of the statement.

Community
  • 1
  • 1
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249