How to Java applet access files inside applet jar file ?
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
- Java Core Technology - Java RegEx, Java XML, Java I/O, Java Misc
- J2EE Frameworks - Hibernate, Spring 2.5, Spring MVC, Struts 1.x, Struts 2.x
- Build Tools - Maven, Archiva
- Unit Test - jUnit, TestNG
- Client Scripts - jQuery
This is handy, thanx for sharing.