I am making a game and have text files inside of my resources folder that I use to store unit data. While running my game from my IDE, I have no problems with the code using Googles Guava to load the files to memory. However, when I tried to package it as a jar, loading text files using the Files methods causes crashes.
I have seen that input resource stream may be a solution to properly load text file data from txt files stored inside of the jar. Could someone please show me how to use the method properly to load from input resource stream directly to a String.
Thank you
String forestString = this.forestkinFileMap.get(forestKin);
URL url = Resources.getResource(forestString);
String text = null;
try {
text = Resources.toString(url, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
UnitTile unit = this.unitTileFactory.processUnitCodeComposite(forestString);
return unit;
Also, this is for the client program, but since its just a matter of loading text files inside the jar, this shouldn't be a relevant factor