Problems using Class.getResourceAsStream() in Java
<p>I'm a bit stuck on a project I'm working on where I want to load in a text file from another folder. I'm using Netbeans, and have, for the purposes of this problem, two folders, one with my class in, and one with the resource in. </p>

<p>The class is in <code>../misc/[ClassName]</code> and the text file I want to load is in <code>../resources/[Name].txt</code></p>

<p>This sounds unbelievably simple, and having done Java for quite a while I really should know this, I assumed the best way of loading this file rather than using just a FileReader, would be to use <code>getResourceAsStream</code>, as shown:</p>

<pre><code>InputStream is = 
        this.getClass().getClassLoader().getResourceAsStream(_filename + ".txt");
</code></pre>

<p>Ideally saving me time and not having to hardcode in a filepath. Now, my problem is I constantly keep getting null returned from the above code, and indeed any other permutation I can put on it. I've tried <code>/resource/filename.txt</code> or <code>resource/filename.txt</code> as parameters, using <code>.getClass().getResourceAsStream</code> as opposed to <code>getClassLoader()</code>, everything is still returning the same result. </p>

<p>Just to avoid any confusion, I've checked the filename and its definitely right and in the right case etc. as well, so that isn't the issue. Any ideas? I know I could just use <code>FileReader</code> to accomplish the same goal, but its kind of a principle thing now!</p>
