title: How to read a text file inside a JAR?
body: <p>What I am attempting to do is store a text file (that won't change) inside the JAR of the program so that it can be read. The purpose of the text file is that it will be read in by one of my classes and the contents of the text file will be added to an <code>JEditorPane</code>. The file will basically be a tutorial and when the user clicks on the option to read the tutorial, the file contents will be read and displayed in a new window that pops up.</p>
  
  <p>I have the GUI portion of it down, but as far as storing the file in the JAR so it can be accessed, I am at a lost. I've read that using an <code>InputStream</code> will work, but after trying a few things I haven't gotten it to work yet.</p>
  
  <p>I also store images in the JAR to be used as icons for the GUI windows. This is accomplished with:</p>
  
  <pre><code>private Image icon = new ImageIcon(getClass()
      .getResource("resources/cricket.jpg")).getImage();
  </code></pre>
  
  <p>But, this doesn't work when trying to get a file:</p>
  
  <pre><code>private File file = new File(getClass.getResource("resources/howto.txt"));
  </code></pre>
  
  <p>Here is my Class as it is now:</p>
  
  <pre><code>public class HowToScreen extends JFrame{
  
  /**
   * 
   */
  private static final long serialVersionUID = -3760362453964229085L;
  private JEditorPane howtoScreen = new JEditorPane("text/html", "");
  private Image icon = new ImageIcon(getClass().getResource("resources/cricket.jpg")).getImage();
  private BufferedReader txtReader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/resources/howto.txt")));
  
  public HowToScreen(){
      setSize(400,300);
      setLocation(500,200);
      setTitle("Daily Text Tutorial");
      setIconImage(icon);
  
      howtoScreen.setEditable(false);
      howtoScreen.setText(importFileStream());
      add(howtoScreen);
      setVisible(true);
  }
  
  public String importFile(){
      String text = "";
      File file = new File("howto.txt");
      Scanner in = null;
  
      try {
          in = new Scanner(file);
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      }
  
      while(in.hasNext()){
          text += in.nextLine();
      }
  
      in.close();
      return text;
  }
  
  public String importFileStream(){
      String text = "";
      Scanner in = new Scanner(txtReader);
  
      while(in.hasNext()){
          text += in.nextLine();
      }
  
      in.close();
      return text;
  }
  }
  </code></pre>
  
  <p>Ignore the <code>importFile</code> method as that is being removed in favor of storing the tutorial file inside the JAR, making the program wholly self contained as I am limited to how much space the program can use.</p>
  
  <p>EDIT:
  After trying all of the suggestions below, I checked to see if my JAR is packaging the text file in it and it is not. When opening the JAR with 7zip, in my resources folder the picture I use for icons is there, but not the text file.</p>