Using ServletOutputStream to write contents to a download file
posted 7 years ago
I am using ServletOutputStream and wrapping it with PrintStream (and tried PrintWriter) to write contents to a RTF file that the user downloads. The input for PrintStream is a String text obtained from a database layer. It contains special characters. I am able to create and download the file successfully, but the special characters are not being displayed correctly.
response.setHeader("Content-disposition","file; filename=sample.rtf"); //RTF file being downloaded
ServletOutputStream stream = response.getOutputStream();
PrintStream out = new PrintStream(stream,true,"UTF-8");
out.println("Dear Dr. AuthorŖ: Thank you for"); //Notice the special character in the string