title: Java read file within static method, using ClassLoader gives FileNotFoundException
body: <p>I want to read a file in my java class. My question is similar <a href="https://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder">to this one</a>, but there are two differences. first, I use a different project layout:</p>
  
  <blockquote>
    <p>/src/com/company/project<br>
    /resources</p>
  </blockquote>
  
  <p>In the resources folder I have a file called "test.txt":</p>
  
  <blockquote>
    <p>/resources/test.txt</p>
  </blockquote>
  
  <p>In the project folder I have a class test.java</p>
  
  <blockquote>
    <p>/src/com/company/project/test.java</p>
  </blockquote>
  
  <p>I want mu java class to be able to read the contents of test.txt in a STATIC METHOD. I've tried the following:</p>
  
  <pre><code>private static String parseFile()
  {
      try
      {
          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  
          String fileURL = classLoader.getResource("test.txt").getFile();
  
          File file = new File(fileURL);
  
  
          ...
      }   
  }
  </code></pre>
  
  <p>and the following paths:</p>
  
  <pre><code>File file1 = new File("test.txt");
  File file2 = new File("/test.txt");
  File file3 = new File("/resources/test.txt");
  </code></pre>
  
  <p>But they all throw a FileNotFoundException when I want to read the file. How can I correctly declare the path to my file in the snippet above with respect to my project setup and the fact that the method needs to be static?</p>