title: How to overwrite existing file during file download rather than create a new file
body: <p>I am using GWT to do file upload, question, how to just overwrite existing file if exists rather create a new file, ex, file(1).doc. Here is my server side code. </p>
  
  <pre><code>protected void service(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
  
          try {
              String modelPath = AutoConstants.PREFIX + "/var/models/";
  
              File file = new File(modelPath + "/" + MODEL_NAME);
  
              if (file.exists()) {
  
                  ServletOutputStream out = response.getOutputStream();
                  DataInputStream in = new DataInputStream(new FileInputStream(
                          file));
  
                  response.setHeader("Pragma", "public");
                  response.setHeader("Cache-Control",
                          "must-revalidate, post-check=0, pre-check=0");
                  response.setHeader("Content-Length",
                          String.valueOf(file.length()));
                  response.setHeader("Content-Disposition",
                          "attachment; fileName=\"" + MODEL_NAME + "\"");
  
                  int i = 0;
                  int BUFSIZE = 8192;
                  byte[] bbuf = new byte[BUFSIZE];
                  while ((in != null) &amp;&amp; ((i = in.read(bbuf)) != -1)) {
                      out.write(bbuf, 0, i);
                  }
  
                  in.close();
                  out.flush();
              }
  
          } catch (Exception e) {
              logger.error("Exception.getModel", e);
              throw new ServletException(e.getMessage());
          }
      }
  </code></pre>