Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

specifying End of Line characters in servlets  RSS feed

 
prabhu kasi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have the following piece of code to write to txt file ...The problem is when i open the txt file , everything is continous and not on separate lines as I want it to be....
Could someone tell me if there is any end of line character i have to specify .... The content type is "text/plain".I tried specifying "\n" but that will work only for text/html and not text/plain.... \n gets printed on the text file .....
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
BufferedReader in = new BufferedReader( new FileReader("/home/lnayar/baais/xmlServlet/"+repName));
while (st != null)
{
out.println(st+"\n");
st = in.readLine();
}
Expected result :::
LATA | WC CLLI | WC NAME | ADSL_LOCATION | ATM FLAG | ATM RELIEF DATE | FRAME FLAG | FRAME RELIEF DATE | GOLD FLAG | GOLD RELIEF DATE | OVERLAY INDICATOR | COUNT
0 | TAMPFLXBRS3 | TAMPAEASTC.O. | TAMPFLXB | OPEN | | CLOSED | 2008-02-29 | NOT _AVAILABLE | | N | 4581 |
I get ::::
\nLATA | WC CLLI | WC NAME | ADSL_LOCATION | ATM FLAG | ATM RELIEF DATE | FRAME FLAG | FRAME RELIEF DATE | GOLD FLAG | GOLD RELIEF DATE | OVERLAY INDICATOR | COUNT\n0 | TAMPFLXBRS3 | TAMPAEASTC.O. | TAMPFLXB | OPEN | | CLOSED | 2008-02-29 | NOT_AVAILABLE | | N | 4581 |
could some one tell me how to get it as per the result ...?
thx
klv
 
Benny Tang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
 
Benny Tang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Instead of using \n, have you try using \r\n as the indicator for new line?
Benny
 
prabhu kasi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
even \r\n dowesnt work...... Those will work only when contenttype is text/html ....but in my case content type is text/plain....
vene tried usimg the line.separator from system property ..still no luck....
any other suggestions pls.....
thx
klv
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried out.println("<BR>")?
 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bosun Bello:
Have you tried out.println("<BR>")?

Hi,
I don't understand why this '\n' is not working for the End of Line in the servlet(But if you see the view source the characters are printed in the next line). You can use <BR> option for the End of Line.
Regards,
M.S.Raman
 
Bhupinder Dhillon
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by prabhu kasi:

out.println(st+"\n");


The println method automatically adds the new line character - so you don't need to add it manually. As for the text being rendered on one line - I suspect your server is running on unix where it adds the EOF as \n and you're trying to open it in MS Windows (Notepad etc). Notepad and some other windows based editors don't recognize the \n character as EOF. I suggest you try this editor, it recognizes both EOF characters.
[ August 22, 2003: Message edited by: Bhupinder Dhillon ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!