In my source code, I created a Java File object pointing to a static image file with the pathname src/a/b/c/img.jpeg
. When the project is built, I did not see the static image file included in the build directory. When I execute the program - how does the pathname still get resolved? I assume the correct pathname will be pointing to build/a/b/c/img.jpeg
but the static image file is not found in the build directory. In addition, does the pathname somehow get converted from src/a/b/c/img.jpeg
to build/a/b/c/img.jpeg
during compilation? Since the file path should be different when it is compiled. Am I misunderstanding something fundamental here?
Asked
Active
Viewed 55 times
0

Hans
- 63
- 1
- 5
-
You can get it as a system resource: ggetClass().getSystemResource(String name). – Just another Java programmer Jan 18 '22 at 18:40
-
More specifically: `SomeClassInCPackage.class.getResource("img.jpeg")` returns a URL that can be passed to ImageIO.read or to an ImageIcon constructor. The URL’s string form can be passed to a JavaFX Image constructor. – VGR Jan 18 '22 at 21:24