title: Create UTF-8 file using HttpServletResponse
body: <p>I am trying to create a UTF-8 file "myFile.aaa" using HttpServletResponse (HttpServlet). The reason why I need this to be UTF-8 is because it might contain special non-printable characters.</p>
  
  <p>However, code below seems to create ANSI-encoded file. At least that is what Notepad++ says, and what I can see reading chars from this file. What am I doing wrong?</p>
  
  <p>Thanks</p>
  
  <pre><code>public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
      {
          res.setHeader("Content-Type", "application/octet-stream; charset=UTF-8");
          res.setHeader("Content-Disposition","attachment;filename=myFile.aaa");
          res.setCharacterEncoding("UTF-8");
          ServletOutputStream os = res.getOutputStream();
          os.print("Hello World");
          os.flush();
          os.close();
      }
  </code></pre>