title: Java ImageIO.write to classpath?
body: <p>I am trying to use the <code>ImageIO</code> class to save an image and then get the resource using an input stream. My problem is that I keep getting a <code>NullPointerException</code> whenever I try to create the input stream. If I simply go and put an image file in the class path, it works. Here is my code:</p>
  
  <pre><code>ImageIO.write(image, "png", new File("temp.png"));
  InputStream imgIs = AptCap.class.getResourceAsStream("temp.png");
  byte[] imgData = new byte[imgIs.available()]; // I get null here.
  </code></pre>
  
  <p>I have also tried specifying direct locations to files on the C drive for both of them, but I still get a null pointer exception. I would rather not do that anyway, but just keep it in the classpath (for purposes of multi OS support).</p>