Reputation: 13
I just started a new game project and I want to create the world by reading a file.
In Eclipse everything is just fine and the file is successfully loaded. The images that are used are being loaded as well.
But if I compile the project and execute the .jar
the images still work but the file could not be found.
I loaded the image by using the classpath:
ImageIO.read(SpriteSheet.class.getResourceAsStream("..."));
and the file by using the path:
new File("...")
They are both in the same folder and I do not now why this does not work because in Eclipse everything just worked fine but after compiling it does not work anymore.
Upvotes: 1
Views: 313
Reputation: 10086
Assuming you're using relative paths,
When you use getResoureAsStream
you can load any file in your classpath.
But when you use new File
your file must reside in the current working directory or in any folder defined in the operating system's path environment variable (not necessarily your classpath).
Your Eclipse is probably able to pick up the file because it is executing your program from where the file is. You are not able to do the same because you're executing the program from elsewhere.
Upvotes: 1