Replacing FileInputStream with getResourceAsStream
<p>I am currently reading in a public key file using the following code:</p>

<pre><code>    // Read Public Key.
    File filePublicKey = new File(path + "/public.key");
    FileInputStream fis = new FileInputStream(path + "/public.key");
    byte[] encodedPublicKey = new byte[(int) filePublicKey.length()];
    fis.read(encodedPublicKey);
    fis.close();
</code></pre>

<p>However, I wish to include the key files in with my jar. I have dragged the key files into my project in eclipse and I am trying to load the public key using the following to replace what is above:</p>

<pre><code>    InputStream is = getClass().getResourceAsStream( "/RSAAlgorithm2/public.key" );
    byte[] encodedPublicKey = new byte[(int) 2375];
    is.read(encodedPublicKey);
    is.close();
</code></pre>

<p>However I keep getting a NullPointerException. </p>

<blockquote>
  <p>java.lang.NullPointerException    at RSA.LoadKeyPair(RSA.java:122)    at
  RSA.main(RSA.java:31)</p>
</blockquote>

<p>Is this because I am incorrectly loading in the file? Can files be dragged into eclipse and loaded like this or is it a requirement to have them seperate from the JAR?</p>
