kbz
kbz

Reputation: 1006

Referencing a file from inside a jar

How do I reference a file from inside the jar in the packages? Because right now it's only looking for the file in the directory that the jar file is in.

I have packed the file inside of the jar correctly, but I'm not sure how to refer to it.

Upvotes: 0

Views: 169

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136122

See Class.getResourceAsStream API

Upvotes: 1

Joop Eggen
Joop Eggen

Reputation: 109613

URL url = getClass().getResource("..../.../...");
InputStream in = getClass().getResourceAsStream("..../.../...");

Either absolute ("/...") or relative to the getClass.

Upvotes: 4

Related Questions