I have managed to find some similar topics to this one, but nothing so far has matched this question exactly. I am making a JavaFX application where the user can add images to be displayed in the application. These images are stored as filepath strings in a text-file database. Since .jar files are read-only, I can't add the image directly into the project, so I have resorted to creating an assets folder that sits just outside the project that the images all sit in.
So the folder structure is:
-> Parent Folder that the .jar file sits in
- Project Folder or .jar file
- src
* classes.java
- assets Folder
* image.jpg
* image2.png
Now, I know that Image image = new Image(getClass().getResourceAsStream(imagePath));
will work if my imagePath
is inside the project folder. But I need the path relative (and outside) the folder.
My first (and, for now, most important) question is how do I state this relative path that breaks out of the folders of the application altogether?
Secondly, is this good practice? If one is making a JavaFX app and wishes to add new images to be stored with the app, is there a better way of doing it?