Why do we only buffer the input in networking? [closed] Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Why do we only buffer the input in networking? [closed] without wasting too much if your time.

The question is published on by Tutorial Guruji team.

So I learned recently that the standard basic networking in Java goes like this:

out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));

I just want to clarify, so for the output we don’t use a BufferedWriter because that’s the job on the server’s side? Would it be wrong to do something like this:

out =  new BufferedWriter(PrintWriter(echoSocket.getOutputStream(), true));


From the Java documentation:


Most of the examples we’ve seen so far use unbuffered I/O. This means each read or write request is handled directly by the underlying OS. This can make a program much less efficient, since each such request often triggers disk access, network activity, or some other operation that is relatively expensive.

To reduce this kind of overhead, the Java platform implements buffered I/O streams. Buffered input streams read data from a memory area known as a buffer; the native input API is called only when the buffer is empty. Similarly, buffered output streams write data to a buffer, and the native output API is called only when the buffer is full.

Yes, “buffered” input AND output is usually a Good Idea.



I don’t see anything wrong with PrintWriter. Especially if I wanted to do “printf()” style text I/O directly to the socket.

We are here to answer your question about Why do we only buffer the input in networking? [closed] - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji