P
P
pshevnin2021-05-17 01:03:45
Java
pshevnin, 2021-05-17 01:03:45

How to correctly write the path to a .png image in java?

Hello, I'm trying to set the path to the image in java. The image is located in the data folder, the data folder itself lies parallel to the src folder. The line where the image is read:

Image cellTexture = new Image(getClass().getResourceAsStream("data\\Cell.png"));
. I tried everything I found on the internet and nothing works. In another project, the same path correctly leads to a file (text) with the same location. Thanks for the advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-05-17
@pshevnin

getClass().getResourceAsStream()
the image file must be located in the directory resources/data
Here is a similar question - https://stackoverflow.com/questions/14089146/file-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question