File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 33import org .json .JSONObject ;
44
55import java .io .*;
6+ import java .nio .charset .StandardCharsets ;
67
78public 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 ();
You can’t perform that action at this time.
0 commit comments