title: When I download Excel from a folder with java I get this error " the format and extension of the .xls file do not match. The file may be damaged"
body: <p>as the title says, when I download an excel sheet from a folder I get this message</p>
  
  <p>This is my code</p>
  
  <pre><code>RequestMapping(value = "/descargar-datos-entrada/{idSimulacion}", method = RequestMethod.GET)
      public void descargarDatosEntrada(@PathVariable("idSimulacion") String idSimulacion, HttpServletResponse response)
              throws IOException {
          Properties properties = new Properties();
          properties = Util.getProperties("mongo");
          FileInputStream inputStream = null;
          response.setContentType("application/vnd.ms-excel");
          response.setHeader("Content-Disposition", "attachment; filename=Hoja-Resultados-Descarga.xls");
  
          try {
  
              Simulacion simulacion = simulacionService.finById(idSimulacion);
              inputStream = new FileInputStream(
                      properties.getProperty("ruta.copia.resultados.excel") + idSimulacion + ".xls");
  
              int c;
              while ((c = inputStream.read()) != -1) {
                  response.getWriter().write(c);
              }
  
          } catch (SimulacionException | IOException e) {
              Util.autoLogError(e);
          } finally {
              if (inputStream != null)
                  inputStream.close();
              response.getWriter().close();
          }
  
      }
  </code></pre>
  
  <p>and the result .xls file would be as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/lrZPO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lrZPO.png" alt="enter image description here"></a></p>
  
  <p>I would appreciate some help or advice, Thanks in advance, it is my first question so excuse me if I didn't ask it correctly.</p>