java: file read, modify outside, then read again, modification not seen
<p>I have set of files which will be served by a servlet based on a parameter. The servlet opens stream to required file, reads, writes to http response and closes the stream. Now this file can be modified manually and saved. Then next time a request comes for this file, servlet opens a stream to this file, writes it to the response, but I see the content is not the modified one, its the old one. </p>

<p>If I restart tomcat, servlet responds with modified content. Can it be made to read the modified content without restart?</p>

<p>Its not tomcat caching, the string read from file reader itself is unchanged.</p>

<p>thanks!</p>

<p>Here's the content of the servlet-</p>

<pre><code>InputStream fhandle=this.getClass().getClassLoader().getResourceAsStream("responses/"+file);

        if(fhandle!=null){
            Reader fr=new InputStreamReader(fhandle);
            PrintWriter out=resp.getWriter();
            int a=-1;
            FileWriter fos=new FileWriter("copyFile.xml"); //to compare what's read with actual file
            while((a=fr.read())&gt;=0){
                fos.write(a);
                out.write(a);
            }
            out.flush();
            fos.close();
            fr.close();
            fr=null;
            fhandle.close();
            fhandle=null;
            System.gc();
        }
        else
            System.out.println(file+" not found");
</code></pre>

<p>After hitting the servlet for first time, I will edit the file and save it. Now again I will hit the same servlet for the same file, and I will not get the edited content.</p>
