Problem locating file in a classpath
<p>I'm trying to read in file content, ex :</p>

<pre><code>public void myMethod(){
     FileInputStream fstream = new FileInputStream(fileLocation);
           // Get the object of DataInputStream
           DataInputStream in = new DataInputStream(fstream);
           BufferedReader br = new BufferedReader(new InputStreamReader(in));
           String strLine;
     while ((strLine = br.readLine()) != null) {
....
....
.....
end while 
end method
</code></pre>

<p>And I have at the begining of the class body <code>private String fileLocation;</code> and at the end of a class I have a getter and setter for it. Now I'm trying inject this file location from spring inside bean from this class and I specify the init-method of this class. But I get error cannot find the specified file as if its not on a classpath but it is inside war file? I'm building the project with maven and I put file in <code>src/main/resources</code> This is the error I get when trying to read file :</p>

<blockquote>
  <p>Error: src\main\resources\ids.txt
  (The system cannot find the path
  specified)</p>
</blockquote>

<p>That is when I tried this :</p>

<pre><code>FileInputStream fstream = new FileInputStream("src\\main\\resources\\ids.txt");
</code></pre>

<p>how to reference the properly from the classpath?</p>

<p><strong>EDIT</strong></p>

<p>When I edit my code according to @BalusC solution , here is how it looks but I still get <code>null</code> error :</p>

<pre><code>ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 
   InputStream input = classLoader.getResourceAsStream("src/main/resources/ids.txt");
   // Get the object of DataInputStream

   BufferedReader br = new BufferedReader(new InputStreamReader(input));
   String strLine;
 while ((strLine = br.readLine()) != null) {
    ....
    ....
    .....
    end while 
    end method
</code></pre>
