Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a JAR resource as a FileStream

Tags:

java

jar

I have a project where I want to access a resource in a JAR from another project. It's not on my classpath, so ClassLoader is not an option. I tried:


new FileInputStream("C:\\mydir\\my.jar!\\myresource.txt");

and received a FileNotFoundException.

JarInputStream might be a possibility, but I want the flexibility of the input filename being a jar resource or just a file on the system (user decides). Is there a class that can do this or do I have to build one myself?

like image 983
User1 Avatar asked Oct 15 '22 10:10

User1


2 Answers

URLs are your friend

URL.openStream.

like image 112
Tom Hawtin - tackline Avatar answered Oct 19 '22 03:10

Tom Hawtin - tackline


Fortunately, the desicion with the "!" symbol doesn't work.

Have a look here:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4730642

like image 21
zeroed Avatar answered Oct 19 '22 03:10

zeroed