wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes BufferedWriter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "BufferedWriter" Watch "BufferedWriter" New topic
Author

BufferedWriter

kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
when I use BufferedWriter, the server program keeps on waiting, that means BufferedWriter does not write.why???PrintWriter does write and my program works.
import java.io.*;
import java.net.*;
class Aa
{
public static void main(String str[]) throws Exception
{
Socket s=new Socket("localhost",33333);
int i=5;
// BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
PrintWriter out=new PrintWriter(s.getOutputStream(),true);
while(true)
{
for(i=5;i>=0;i--)
{
out.println(i+"message from Client");
//bw.write(�message sent to server�);
//bw.flush();
System.out.println("message sent to server");
}

}

}
}
[ April 18, 2004: Message edited by: kriti sharma ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
You probably need to flush() the stream. Or if you're done, simply close() it. Or you can make a PrintStream or PrintWriter which does auto-flush when you call println() - that's what System.out does. See the API for PrintStream and PrintWriter, and look at the constructors that take a boolean argument.


"I'm not back." - Bill Harding, Twister
kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
i did flush and close the BufferedWriter stream but it does not write to the stream.the server program keeps on waiting.PrintWriter works very well.why is this happening?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: BufferedWriter