How can a Java applet access files inside the jar file the applet is stored in?

Often time, we bundle our config file as text file or XML file and store it together with Applet jar file, and deploy it together to client. For instance, an jtest.jar file , include a Java Applet class (jtest.java) and a XML config file.

jtest.jar
  |--jtest.java
  |--config.xml

How can we access the “config.xml” XML file in “jtest.java” class? The simplest solution is using “getResourceAsStream” to get the config.xml file content in InputStream format.

InputStream is = jtest.class.getResourceAsStream("/config.xml");

Done. :)

Please refer to the following website to understand more about the Java’s resource concept.
http://java.sun.com/j2se/1.4.2/docs/guide/resources/resources.html