title: How to delete a file after sending it in a web app?
body: <p>I have a web application. I am using java and spring. The application can create a file and send it to the browser, this is working fine. The way I do it is:</p>
  
  <p>I create the file in a Services class, and the method returns the address to the controller. The controller then sends the file, and it is downloaded correctly. The code for the controller method is this.</p>
  
  <pre><code>@RequestMapping("/getFile")
  public @ResponseBody
  FileSystemResource getFile() {
  
      String address = Services.createFile();
      response.setContentType("application/vnd.ms-excel");
      return new FileSystemResource(new File (address));
  }
  </code></pre>
  
  <p>The problem is that the file is saved in the server, and after many requests it will have a lot of files. I have to delete them manually. The question is: How can I delete this file after sending it? or Is there a way to send the file without saving it in the server?</p>