Reading file inside jar
1 posts in topic
Flat View  Flat View

Posted By:   Archie_Marsden
Posted On:   Sunday, February 22, 2004 01:05 PM

I am running an applet from inside a jar file. I have an xml file inside the same jar, but the applet will not recognize the file. It will recognize the file if I give the fully-qualified path name as follows:

How do I get the applet to look at the file in the jar?

Thanks Archie

Re: Reading file inside jar

Posted By:   Anonymous  
Posted On:   Sunday, February 22, 2004 01:37 PM

Hi, if you want to access any resource file in your classpath (here an xml file in your applet jar), you can do as follow:

InputStream in = MyApplet.class.getClass().getResourceAsStream("/sample/util/cclist.xml");

By the way, if you want to access a file in an external jar, you can open a JarConnection directly on this file, see the java.net.JarURLConnection javadoc for more details.
About | Sitemap | Contact