Question

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());
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top