This tip shows how to read a text file from a jar.


 import java.applet.*;

public class ReadFromJar extends Applet{

  public void init(){

  public void readTextFromJar(String s) {
    String thisLine;
    try {
      InputStream is = getClass().getResourceAsStream(s);
      BufferedReader br = new BufferedReader
         (new InputStreamReader(is));
      while ((thisLine = br.readLine()) != null) {  
    catch (Exception e) {

Create 2 datafiles.

datafile1.txt in the same directory as ReadfromJar.class and datafile2.txt in a subdirectory called test

datafile1  line 1
datafile1  line 2
datafile1  line 3
datafile1  line 4
datafile1  line 5

datafile2  line 1
datafile2  line 2
datafile2  line 3
datafile2  line 4
datafile2  line 5

Create the jar with

 jar cf readjar.jar ReadFromJar.class datafile1.txt test\datafile2.txt

Try with the follwing HTML page

<APPLET CODE=ReadFromJar.class width=1 height=1 archive=readjar.jar>
See java console for output</BODY></HTML>