I have seen many topics on this subject, but non of them work as the resource cannot be in a static method, and I need a static method to make the getters work so I can actually load the world file in the world class.
it is different please read again, the Resource doesn't work as the method HAS to be static.
https://stackoverflow.com/questions/37257553/java-game-eclipse-cant-locate-txt-after-export-to-jar#=
Reading a resource file from within jar
Those had no answers so admins please read before saying the same thing to the others asking the same question. If I come out as a bit of an asshole, I apologize as I've been stuck on this problem, for the last few days trying to get it to fetch it from the resources instead of from the hard drive.
I have a world being created in the World file by using this line
world = new World(handler,"res/worlds/world1.txt");
it then renders the world using this funtion
loadWorld(path);
It then returns back a string to the Utilites
String file = Utilities.loadFileAsString(path);
Here is the utilites class, which converts all the spaces in the world file
public static String loadFileAsString(String path){
StringBuilder builder = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String line;
while((line = br.readLine()) != null)
builder.append(line + "\n");
br.close();
} catch(IOException e){
e.printStackTrace();
}
return builder.toString();
}
It works fine in eclipse, but after it doesn't load the world file, because it doesn't fetch it via resources, my question is how would I go about doing this.