How can I read a file from the applet's JAR file?

John Zukowski

Use the getResourceAsStream() method to get the file in the JAR as an InputStream. Then just read it:

import java.awt.*;
import java.applet.*;

public class Read extends Applet {

  TextArea ta = new TextArea();

  public void init() {
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    try {
      InputStream in = 
      InputStreamReader isr = 
        new InputStreamReader(in);
      BufferedReader br = 
        new BufferedReader(isr);
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      String line;
       while ((line = br.readLine()) != null) {
    } catch (IOException io) {
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact