Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Amazing problem!! please help...  RSS feed

 
prasad bhn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
i dont know why the below code doesn't work when i remove line number 9,i.e., "out.flush()" . Here we need to flush the stream forcefully!! why so?
please throw focus.
Thanks,
Prasad Bh.
1 import java.io.*;
2 public class testIO
3 {
4 public static void main (String [] argc) throws IOException
5 {
6 PrintWriter out = new PrintWriter(System.out);
7 out.println("Hello World!") ;
8 out.flush();
9 }
10 }
 
Bryan Fagan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad:
You are missing one thing. The PrintWriter has constructor that tells the PrintWriter to auto flush the buffer. Otherwise, you have to flush it yourself.
Constructor for PrintWriter
PrintWriter(OutputStream out, boolean autoFlush)
Your code with the change:
import java.io.*;
2 public class testIO
3 {
4 public static void main (String [] argc) throws IOException
5 {
6 PrintWriter out = new PrintWriter( System.out, true );
7 out.println("Hello World!") ;
8
9 }
10 }
-Bryan :-)
Originally posted by prasad bhn:
hi guys,
i dont know why the below code doesn't work when i remove line number 9,i.e., "out.flush()" . Here we need to flush the stream forcefully!! why so?
please throw focus.
Thanks,
Prasad Bh.
1 import java.io.*;
2 public class testIO
3 {
4 public static void main (String [] argc) throws IOException
5 {
6 PrintWriter out = new PrintWriter(System.out);
7 out.println("Hello World!") ;
8 out.flush();
9 }
10 }


[This message has been edited by Bryan Fagan (edited June 02, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!