1

I try to get a file in my bundle with:

File file = new File(bundleContext.getBundle().
getResource("image/logo.jpg").toURI());

The result is a IllegalArgumentException with the cause "URI scheme is not "file".

This is logical, but how should i open a file with this URL (bundle://28/image/logo.jpg)?

If i use the regular ClassLoader i get the same result.

EDIT:

My Solution:

URL url = this.getClass().getClassLoader().getResource("image/logo.jpg");
InputStream in = new BufferedInputstream(url.openStream());
nik the lion
  • 458
  • 1
  • 9
  • 22

1 Answers1

1

You cannot open a file since there might not be a file ... So just get the input stream instead. That works for all URLs/URIs.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55