title: How to use existing text files for JUnit tests
body: <p>I want to unit test a class that manipulates contents of text files. I have a set of existing text files to serve as test cases. How and where do I store these text files that would be used by the JUnit tests?</p>
  
  <p>I've tried putting them in the same directory with the unit test .Java file and tried to access them, but I get a file not found:</p>
  
  <pre><code>File baseFile = new File("base_test.txt");
  assertTrue(baseFile.exists());
  </code></pre>
  
  <p><strong>EDIT:</strong>
  as per the answers, I've tried getting the files using <code>ClassLoader</code>. The files are there, however when I tried to use the <code>InputStream</code> for those files, I am getting a <code>"Stream Closed"</code> Exception.</p>
  
  <p>I've tried getting the <code>InputStream</code> both from the file and the URL:</p>
  
  <pre><code>    FileInputStream in = new FileInputStream(new File(filename));
  ...
      InputStream in = baseUrl.openStream();
  </code></pre>
  
  <p>Same exception.</p>