Skip to content

Commit 5153710

Browse files
committed
Fix ressource loading in JsonReader
1 parent 7c33666 commit 5153710

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/main/java/config/LootConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ public class LootConfig {
99
public static final int dropCommon = 60;
1010
public static final int dropRare = 35;
1111
public static final int dropLegendary = 5;
12-
public static final JSONObject itemList = readJson(LootConfig.class.getResource("/items.JSON").getPath());
12+
public static final JSONObject itemList = readJson("/items.JSON");
1313
}

src/main/java/utilities/JsonReader.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
import org.json.JSONObject;
44

55
import java.io.*;
6+
import java.nio.charset.StandardCharsets;
67

78
public class JsonReader {
89

910
public static JSONObject readJson(String fileName) {
11+
InputStream inputStream = JsonReader.class.getResourceAsStream(fileName);
1012
StringBuilder sJson = new StringBuilder();
11-
try (BufferedReader br = new BufferedReader(new FileReader(new File(fileName)))) {
12-
String str;
13-
while ((str = br.readLine()) != null) {
14-
sJson.append(str).append("\n");
13+
try {
14+
assert inputStream != null;
15+
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
16+
String str;
17+
while ((str = br.readLine()) != null) {
18+
sJson.append(str).append("\n");
19+
}
1520
}
1621
} catch (IOException e) {
1722
e.printStackTrace();

0 commit comments

Comments
 (0)