I am new to socket programming and learning the basics now. I have been seeing in sample programs that, the client gets the input from server socket thro DataInputStream at some places and through BufferedReader(wrapping the InputStreamReader) at some other places? What exactly differentiates the usage of the two classes here? What to use when?
An important difference between the ...Stream classes and the ...Reader/...Writer classes is that streams work with binary data (in other words, raw bytes), while readers and writers work with character data. In going from one to the other there's always an encoding or decoding of data involved.
The en-/decoding step can't be done in a meaningful way unless one knows what encoding was used. Common encodings are US-ASCII, UTF-8 and other Unicode variants, MacRoman, ISO-8859-1 and CP1252. Furthermore, each platform (Windows, Linux, OS X, ...) has its own default encoding, so if no encoding is specified, the JVM will choose one - which may well be the wrong one.
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset.
A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream. you can read following links [DataInputStream] [BufferedReader].
Related to your question i think this forum Discussion already done. [ July 23, 2008: Message edited by: Mandar Khire ]
Millions saw the apple fall, but Newton asked why.
subject: What is the difference between DataInputStream and BufferedReader?