title: Java - Get string path of resource files
body: <p>I want to access to get the string path to my resource key files. If I debug the project in eclipse, everything works like a charm but if I export the project to a runnable .jar file - the project can't access the key files because the path is wrong.</p>
  
  <pre><code>PUBLIC_KEY_PATH = "src/resources/public.key";
  PRIVATE_KEY_PATH = "src/resources/private.key";
  </code></pre>
  
  <p>But how do I get the right path for the runnable .jar file? I don't want to get the URL or anything else - I want to get the string path.</p>
  
  <p>I hope that someone can help me.</p>
  
  <hr>
  
  <p><strong>Solution:</strong></p>
  
  <pre><code>public static String PUBLIC_KEY_PATH = "/resources/public.key";
  public static String PRIVATE_KEY_PATH = "/resources/private.key";
  </code></pre>
  
  <p>I'm using an <code>InputStream</code> to read the file content:</p>
  
  <pre><code>InputStream in = ExampleClass.class.getResourceAsStream(PUBLIC_KEY_PATH);
  ObjectInputStream oin = new ObjectInputStream(new BufferedReader(in));
  </code></pre>
  
  <p>There we go ;)</p>