title: Read file from classpath with Java 7 NIO
body: <p>I've googled around for quite a while for this, but all the results point to pre-Java 7 NIO solutions. I've used the <a href="http://docs.oracle.com/javase/tutorial/essential/io/file.html" rel="noreferrer">NIO stuff</a> to read in files from the a specific place on the file system, and it was so much easier than before (<code>Files.readAllBytes(path)</code>). Now, I'm wanting to read in a file that is packaged in my WAR and on the classpath. We currently do that with code similar to the following:</p>
  
  <pre><code>Input inputStream = this.getClass().getClassLoader().getResourceAsStream(fileName);
  ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
  
  /* iterate through the input stream to get all the bytes (no way to reliably find the size of the 
   *     file behind the inputStream (see http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#available()))
   */
  int byteInt = -1;
  try
  {
      byteInt = inputStream.read();
      while (byteInt != -1)
      {
          byteStream.write(byteInt);
          byteInt = inputStream.read();
      }
  
      byteArray = byteStream.toByteArray();
      inputStream.close();
      return byteArray;
  }
  catch (IOException e)
  {
      //...
  }
  </code></pre>
  
  <p>While this works, I was hoping there was an easier/better way to do this with the NIO stuff in Java 7. I'm guessing I'll need to get a <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html" rel="noreferrer">Path</a> object that represents this path on the classpath, but I'm not sure how to do that. </p>
  
  <p>I apologize if this is some super easy thing to do. I just cannot figure it out. Thanks for the help.</p>