Arashigor
Arashigor

Reputation: 171

Java can't open file with relative path

I'm trying to change dock icon for jar file, but it works only with absolute path:

Image image = Toolkit.getDefaultToolkit().getImage("/User/Project/src/main/resources/icon.png");

even if files are in the same package this doesn't work:

Image image = Toolkit.getDefaultToolkit().getImage("./icon.png");

Project Structure: enter image description here

Upvotes: 1

Views: 583

Answers (1)

aUserHimself
aUserHimself

Reputation: 1597

You should try this:

Toolkit.getDefaultToolkit().getImage("icon.png");

It will search the file name icon.png inside main/resources.

UPDATE:

If still not working, this should do the trick:

Toolkit.getDefaultToolkit().getImage("src/main/resources/icon.png");

Upvotes: 1

Related Questions