Printwriter to print new lines
-
23-12-2019 - |
Question
I am printing a text file using Printwriter, in servlets.
PrintWriter writer = response.getWriter();
while ((text = reader.readLine()) != null)
{
writer.print(text);
}
Though this prints the txt file, it is not printing any new lines.
I've tried
LINE ="\n"
writer.print(text + LINE);
doesn't work.
also tried using println, still no use.
any suggestions??
Solution
Use <br>
tag for html.
LINE ="<br>"
writer.print(text + LINE);
OTHER TIPS
- For text file we need to set response contentType as
text
: Example:response.setContentType("text;charset=UTF-8");
- For newLine by
PrintWriter
we need to print byprintln
: example:out.println("abcd....");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow