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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "BufferedWriter" Watch "BufferedWriter" New topic


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);
out.println(i+"message from Client");
//bw.write(�message sent to server�);
System.out.println("message sent to server");


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

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?
I agree. Here's the link: http://aspose.com/file-tools
subject: BufferedWriter
Similar Threads
Dynamic IP address and socket programming.
client-serer...plz help
chat program....need help
Socket program for linux
little chat program