• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with "System.out.write"  RSS feed

 
Emilian Chmiel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I got question about "System.out.write":



why "System.out.write('\n');" is nessesery to print "X" on console?
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use System.out.write at all. It is not intended for writing things to the terminal, but for special handling of streams of bytes. Only use \n if somebody specifically says they want the LF character. Use:-
System.out.println(b);

If you fail to write a line end with the write method, the buffer is never flushed and the X remains in the buffer for ever. There are doubtless lots of places you can read about buffers: try the Java™ Tutorials or Wikipedia.

[edit]If you really want to use write tryI have never tried that code.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out is a PrintStream and the write method comes from there.  I believe the write method buffers its output until it sees a newline character.  That probably makes writing faster.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!