title: Reading a text file in my .jar
body: <p>Lets say I'm making a program that needs to copy all the lines in a .txt file within my .jar file. it is in the package <code>program.files</code> and it is named text.txt. I've been looking all over the internet, and i cant find what I'm looking for. i think that this idea:</p>
  
  <pre><code>public String readSpecificFromJar(String dir, int line) {
      String read = null;
      try {
          InputStream in = getClass().getResourceAsStream(dir);
          BufferedReader bufferedReader = new BufferedReader(
                  new InputStreamReader(in));
  
          /**
           * declare string variable and prime the read
           */
          read = bufferedReader.readLine();
  
          for (int i = 1; i &lt; line; i++) {
              read = bufferedReader.readLine();
          }
  
          bufferedReader.close();
      } catch (IOException ioexception) {
          Dialogs.fail("Could not read txt file from the JAR!!! Error Code: 06");
      }
  
      return read;
  }
  </code></pre>
  
  <p>would work, but i tried that and it gave me all kinds of errors. what i think the problem would be is declaring the <code>InputStream in</code> the way it does it want the file to be right there with the Main method. how would i change this so it is not the case? thanks in advance!</p>
  
  <p>EDIT:
  due to some confusion, i want to clear this up. for the String <code>dir</code> i am entering <code>files/text.txt</code>. it wont work. how do i fix this?</p>
  
  <p>EDIT 2:
  OK i feel like the problem isn't getting across, and I'm kinda getting aggravated, mainly because I'm pretty tired. the code that WORKS for a different program is up above, where the <code>dir</code> is simply <code>"text.txt"</code></p>
  
  <p>THIS DOESN'T WORK FOR WHAT I'M DOING AND IM NOT SURE WHY. again, the file is IN THE CLASSPATH so <code>dir</code> is only <code>"text.txt"</code>. I want my .txt file to be <code>"files/text.txt"</code>. How do i do this?</p>
  
  <p>EDIT 3:
  I dont know if i mentioned it, but my .txt file is INSIDE my jar. just to clear up the confusion. so really, the path of the .jar file shouldn't matter, as in I shouldn't have to type it in with the <code>dir</code>. also, the main class is in the package <code>main</code> and the .txt file is in the package <code>files</code> all within the same program named <code>copy</code>. also, i tried moving the txt file to the same package as the <code>main</code> class, also didn't work.</p>
  
  <p>EDIT 4:
  by the way, the package that holds the method for reading from the jar is <code>IO</code>. as in the class <code>io</code> is inside the package <code>IO</code>. all of my files such as images and txt are in the package <code>files</code>. just thought id clear that up. i tried moving the txt file to the package of the <code>io</code> class, and that worked, but if its in any other package, even if i include the package name in the <code>dir</code> it wont work. any ideas as to why?</p>