I have used
File file = new File(Game.class.getResource("Tiles.txt").getFile())
to get the txt file from my resources folder and it works fine when inside the IDE but when building to a jar and running outside of the environment it throws file not found errors (which i saw through running in CMD).
I use a similar method to get all my images and sprite sheets:
BufferedImage loadedImage = ImageIO.read(Game.class.getResourceAsStream("EG.png"));
how do they differ in importing files and why is my path incorrect?
Error CMD gives: https://i.stack.imgur.com/4gEIZ.jpg
C:\Users\Taka\Desktop>java -jar ProjectC-Revamped.jar
java.io.FileNotFoundException: file:\C:\Users\Taka\Desktop\ProjectC-Revamped.jar!\Tiles.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Tiles.<init>(Tiles.java:16)
at Game.<init>(Game.java:91)
at Game.main(Game.java:192)
java.io.FileNotFoundException: file:\C:\Users\Taka\Desktop\ProjectC-Revamped.jar!\Maps\Map.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Map.<init>(Map.java:20)
at Game.<init>(Game.java:94)
at Game.main(Game.java:192)