title: Problem with downloading utf-8 encoded csv file using Spring boot and HttpServletResponse
body: <p>I needed to create and download a <em>utf-8</em> encoded csv file in my spring boot application. 
  The problem is that <em>Excel 2019</em> is unable to open it correctly and as you may guess all those utf-8 characters are shown as strange symbols. I read somewhere that adding <em>BOM</em> characters to the start of csv file would solve the problem. I did it manually and it works actually. But, when I use the <em>HttpServletResponse</em> as follows it doesn't work:</p>
  
  <pre><code>HttpServletResponse response = ...;//coming from rest api call
  response.addHeader("Content-Type", "text/csv; charset=UTF-8");
  response.addHeader("Content-Disposition", "attachment; filename=test.csv");
  response.setCharacterEncoding("UTF-8");
  
  /*write o response file csvWriter and flush/close it*/
  try {
      ServletOutputStream outputStream = response.getOutputStream();
      outputStream.write(new byte[]{239, 187, 191});//add utf-8 BOM bytes
      outputStream.write("some,utf8,text".getBytes());
      outputStream.close();
  } catch (IOException e) {
      //handle exception
  }
  </code></pre>
  
  <p>I checked the generated <em>test.csv</em> file with some <em>HEX</em> viewer tool to see if there are those <em>BOM</em> bytes at the start of file. Very strangely they weren't there. Although I explicitly write them to the file, they are haven't been written at the start of file. very very stragne. 
  Can anybody help?!</p>