Getting the location of a folder next to my .jar file

Hippopotoman :

In a program I am making, I need to access images in a folder placed alongside it. The program works fine when I run it with Eclipse, but when I export it to a .jar file, it does not get the location of the folder properly.

File roomF = new File("Assets/Rooms/1/0.png");

In the IDE, roomF refers to the correct location:

C:\Users\[Username]\Desktop\Eclipse Java\[Project name]\Assets\Rooms\1\0.png

However, in the .jar file, it refers to this:

C:\Users\[Username]\Assets\Rooms\1\0.png.

How can I fix this?

Diogo Andrade :

You should not have resources outside of your JAR or dependencies that need a local path in order to work. Create a resource folder in your project and load the file from there.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=361467&siteId=1