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());

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.