title: Add txt files to a runnable JAR file
body: <p>I'm trying to make a runnable jar file and I'm having problems with my .txt files.</p>
  
  <p>My program also have images, but fortunately I've figured out how to manage them. I'm using something like this with them and it works just fine both Eclipse and the jar:</p>
  
  <pre><code>logoLabel.setIcon(new ImageIcon(getClass().getResource("/logo.png")));
  </code></pre>
  
  <p>My problem is when I've something like this in one of my classes:</p>
  
  <pre><code>try {
      employeeList =  (TreeSet&lt;Employee&gt;) ListManager.readFile("list/employeeList.txt");
  } catch (ClassNotFoundException i) {
      i.printStackTrace();
  } catch (IOException i) {
      i.printStackTrace();
  }
  </code></pre>
  
  <p>And this in the class ListManager that I use to read my lists serialized in the .txt files:</p>
  
  <pre><code>public static Object readFile(String file) throws IOException, ClassNotFoundException {
      ObjectInputStream is = new ObjectInputStream(new FileInputStream(file));
      Object o = is.readObject();
      is.close();
      return o;
  }
  </code></pre>
  
  <p>I also have a similar method to write in the files.</p>
  
  <p>I've tried several combinations that I've found here:</p>
  
  <p><a href="https://stackoverflow.com/questions/2671796/how-to-include-text-files-with-executable-jar">How to include text files with Executable Jar</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18091046/creating-runnable-jar-with-external-files-included">Creating Runnable Jar with external files included</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10452825/including-a-text-file-inside-a-jar-file-and-reading-it">Including a text file inside a jar file and reading it</a></p>
  
  <p>I've also tried with slash, without slash, using openStream, not using openStream... But or I get a NullPointerException or it doesn't compile at all...</p>
  
  <p>Maybe is something silly or maybe is a concept error that I've of how URL class works, I'm new to programming...</p>
  
  <p>Thank you very much in advance for your advice!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It's me again... The answer Raniz gave was just what I needed and it worked perfect, but now my problem is with the method that I use to write in the files...</p>
  
  <pre><code>public static void writeFile(Object o, String file) throws IOException {
      ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(file));
      os.writeObject(o);
      os.close();
  }
  
  try {
     ListManager.writeFile(employeeList.getEmployeeList(), "lists/employeeList.txt");
  } catch (IOException i) {
     i.printStackTrace();
  }
  </code></pre>
  
  <p>Could you help me please? I don't know what I should use to replace FileOutputStream, because I think there is the problem again, am I right?</p>
  
  <p>Thank you very much!</p>