In a Servlet, I am using the following code to download the file. The next line characters “\n\r” are not working. Instead of new line, it showing boxes. Can any one help to solve this problem?
String temp = "hello"+"\n\r"+"welcome";
response.setContentType("text/plain");
response.setHeader("Content-Disposition","attachment;filename=sample.txt");
PrintWriter out = response.getWriter();
out.write(temp);
out.flush();
out.close();
Instead of hard-coding new line characters, you can just use the
printlnmethod:If this is not appropriate for some reason, you might consider obtaining the line separator from the
line.separatorSystem property: