title: Accessing a file inside a .jar file
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/403256/how-do-i-read-a-resource-file-from-a-java-jar-file">How do I read a resource file from a Java jar file?</a>  </p>
  </blockquote>
  
  
  
  <p>Starting to go completely bonkers over this after googling for hours. I've also seen variations of the question on the site but can't seem to get it working. A JFrame needs to read data from a ini file and I've created a method to open said file. Said file is stored in a folder called resources inside a jar file. </p>
  
  <pre><code>private BufferedReader openIniFile(String filename){
      BufferedReader brReader = null;                 
      try{
          File fileObj = new File(this.getClass().getResource("/resources/" + filename).toURI()); // The fileobject of the file to read
          if(fileObj.exists())                                            
              brReader = new BufferedReader(new FileReader(fileObj));                     
  
      } catch(Exception e){
          System.err.println("Exception while opening file: " + e.getMessage()); 
  
      }
  
      return null;
  }
  </code></pre>
  
  <p>This of course works perfectly when I'm running the code after compilation, but throws an exception after being exported to a .jar file. I've looked into using InputStream, FileInputStream but can't seem to find a solution that would work.</p>
  
  <p>How can I make the jar file recognize the resource?</p>