From d3106bf41e099d329d9db330ab09e167519fce25 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 27 Apr 2024 04:56:48 +1000 Subject: Fix fairy soul json being locked by the first instance of the game (#1114) --- .../moulberry/notenoughupdates/miscfeatures/FairySouls.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java index 52ce46a1..e447e4a9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java @@ -46,9 +46,11 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -317,11 +319,9 @@ public class FairySouls { public void loadFoundSoulsForAllProfiles(File file, Gson gson) { allProfilesFoundSouls = new HashMap<>(); String fileContent; - try { - fileContent = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) - .lines() - .collect(Collectors.joining(System.lineSeparator())); - } catch (FileNotFoundException e) { + try (BufferedReader br = Files.newBufferedReader(file.toPath())) { + fileContent = br.lines().collect(Collectors.joining(System.lineSeparator())); + } catch (IOException e) { // it is possible that the collected_fairy_souls.json won't exist return; } -- cgit