title: Java File release resource
body: <p>I am using SpringFramework Web MVC and inside the servlet handleRequestInternal, I created a variable to access a file in the local filesystem, i.e.</p>
  
  <pre><code>protected ModelAndView handleRequestInternal(HttpServletRequest request,......
  {
  ......
   File file = new File(rssPath);
   if( !file.exists() ) {
    file.createNewFile();
    FileWriter outFile = new FileWriter(rssPath);
    outFile.write(rssJson);
    outFile.flush();
    //file = null;
   }
  }
  </code></pre>
  
  <p>The question is, if I don't set the file to null, the file will still be in use and I can't write to it. </p>
  
  <p>I have to wait a few seconds, probably until GC comes to collect. </p>
  
  <p>Looking at the File API, I don't see any method such as close() to release the resources.</p>
  
  <p>So how do I destroy the file reference properly (without setting it to null, am I missing something ?) ?</p>