Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes I/O and Streams and the fly likes What is the difference between DataInputStream and BufferedReader? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "What is the difference between DataInputStream and BufferedReader?" Watch "What is the difference between DataInputStream and BufferedReader?" New topic

What is the difference between DataInputStream and BufferedReader?

Shaik Muhammad
Ranch Hand

Joined: Jul 16, 2008
Posts: 36

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?

Please explain

Shaik Muhammad
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2846

Its implied that the BufferdReader provides buffering capabilities .
Look the specifications for more information.

Hope this helps

|Asking Good Questions|
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
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.
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 557

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

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.
I agree. Here's the link:
subject: What is the difference between DataInputStream and BufferedReader?
It's not a secret anymore!