title: How to really read text file from classpath in Java
body: <p>I am trying to read a text file which is set in CLASSPATH system variable. Not a user variable.</p>
  
  <p>I am trying to get input stream to the file as below:</p>
  
  <p>Place the directory of file (<code>D:\myDir</code>)in CLASSPATH and try below:</p>
  
  <pre><code>InputStream in = this.getClass().getClassLoader().getResourceAsStream("SomeTextFile.txt");
  InputStream in = this.getClass().getClassLoader().getResourceAsStream("/SomeTextFile.txt");
  InputStream in = this.getClass().getClassLoader().getResourceAsStream("//SomeTextFile.txt");
  </code></pre>
  
  <p>Place full path of file (<code>D:\myDir\SomeTextFile.txt</code>)in CLASSPATH and try the same above 3 lines of code.</p>
  
  <p>But unfortunately NONE of them are working and I am always getting <code>null</code> into my InputStream <code>in</code>.</p>