title: IOException: StreamClosed Without Apparent Cause
body: <p>I have created a program in Java that I want packaged into an executable jar file. I want this program to take images from the jar file and display them. I created an abstract class with a method to take a String filename and return an Image object. However, when I try to run this method, it fails and produces an "IOException: Stream closed" error.</p>
  
  <p>I can't find anything on why the stream is closed. I don't have any other input streams in my program, as far as I know. Using the method in a new main with nothing but a JFrame set-up still produces the same error. </p>
  
  <p>Whether I call the image file only by its name (i.e. "example.png") or use its relative path (i.e. "/src/icons/example.png"), OR use its absolute path (i.e. "C:/Users/My_Name/Desktop/EXAMPLE/src/icons/example.png") I receive the same stream closed error. </p>
  
  <pre><code>public static Image importImage(String fileName) throws IOException {
      Image img = null;
  
      byte[] data = new byte[10000];
  
      BufferedInputStream bis = new BufferedInputStream(      Thread.currentThread().getClass().getResourceAsStream(fileName));
  
      int byteRead = bis.read(data, 0, 10000);
  
      img = Toolkit.getDefaultToolkit().createImage(data);
  
      return img;
  }
  </code></pre>
  
  <p>I expect the program to accept the name of the image file in question, and return an Image object. The image file is on the project's classpath, and should be visible.</p>