Link to home
Create AccountLog in
Avatar of MicheleMarcon
MicheleMarconFlag for Italy

asked on

How to open a FileInputStream from an URL?

I have this code that doesn't work:

SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark(new FileInputStream(MyApp.class.getResource("images/myimg.png"))));

Because getResources returns a URL, but FileInputStream can't open a file from a URL.
Of course, I use URL because I don't know the absolute location of my file.

How can I fix this?
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
you can call toUri() on getResource method.

MyApp.class.getResource("images/myimg.png").toURI()