Basically I want to use the icon.png from the utils/images
and not the icon.png fromm the src/app
. They are the same but to keep some project order I want to use the utils folder.
Current code: stage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));
(This is JavaFX code but my problem is based on Java in general)
I heard you can go folders up by using "../icon.png"
I tried that out by putting the icon.png into my src folder (instead of app) and it DID work. But "../" doesn't work twice: "../../icon.png"
will not work (so I can't put my image into the main project folder for instance).
It also works if I try "../images/icon.png"
(images is a folder I just created [not on the screenshot] and I put it into the src folder but not into the app folder like this:
But my problem is that I need to go up 2 folder not just 1 to go back down 2 folders.
Going down is no problem but how do I get up 2 when "../../icon.png"
won't work?
Edit: Actually,
seems to be the correct folder where all the compiled classes are. So this is the start position of my journey to the utils folder (still in the main project folder). My problem is still the same, just to say I now have to go up (or back) 4 folder instead of 2. Any ideas?
Im using IntelliJ, if this helps.
Edit 2: I found out how to go folders up:
File projectFolder = new File(getClass().getResource("").toURI()).getParentFile().getParentFile().getParentFile().getParentFile();
But how to go down the 2 now? And also: Will this line of code stop working when I for instance change my IDE because the .class files in IntelliJ are stored in this "out/..." folder construction but in eclipse it looks different and in NetBeans probably too.
Would it be best to just let the icon.png be in the same folder where the executed classes are to prevent what I just said? ...
Thank you!