title: Why am I getting a NullPointerException when trying to read a file?
body: <p>I use this test to convert txt to pdf :</p>
  
  <pre><code>package convert.pdf;
  
  //getResourceAsStream(String name) : Returns an input stream for reading the specified resource.
  //toByteArray : Get the contents of an InputStream as a byte[].
  
  import java.io.FileOutputStream;
  import java.io.IOException;
  
  import org.apache.commons.io.IOUtils;
  
  import convert.pdf.txt.TextConversion;
  
  public class TestConversion {
  
    private static byte[] readFilesInBytes(String file) throws IOException {
        return IOUtils.toByteArray(TestConversion.class.getResourceAsStream(file));
    }
  
    private static void writeFilesInBytes(byte[] file, String name) throws IOException {
        IOUtils.write(file, new FileOutputStream(name));
    }
  
    //just change the extensions and test conversions
    public static void main(String args[]) throws IOException {
        ConversionToPDF algorithm = new TextConversion();
        byte[] file = readFilesInBytes("/convert/pdf/text.txt");
        byte[] pdf = algorithm.convertDocument(file);
        writeFilesInBytes(pdf, "text.pdf");
    }
  
  }
  </code></pre>
  
  <p>Problem:</p>
  
  <pre>
  Exception in thread "main" java.lang.NullPointerException
      at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
      at org.apache.commons.io.IOUtils.copy(IOUtils.java:999)
      at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:218)
      at convert.pdf.TestConversion.readFilesInBytes(TestConversion.java:17)
      at convert.pdf.TestConversion.main(TestConversion.java:28)
  </pre>
  
  <p>I use the debugger, and the problem seems to be located here :</p>
  
  <pre><code>  private static byte[] readFilesInBytes(String file) throws IOException {
        return IOUtils.toByteArray(TestConversion.class.getResourceAsStream(file));
    }
  </code></pre>
  
  <p>What is my problem?</p>