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??

Was it helpful?

Solution

Use <br> tag for html.

LINE ="<br>"
writer.print(text + LINE);

OTHER TIPS

  1. For text file we need to set response contentType as text: Example: response.setContentType("text;charset=UTF-8");
  2. For newLine by PrintWriter we need to print by println: example: out.println("abcd....");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top