my dog learned polymorphism*
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
Author

What is the difference between DataInputStream and BufferedReader?

Shaik Muhammad
Ranch Hand

Joined: Jul 16, 2008
Posts: 36
Hi,

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
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

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


Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41102
    
  45
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.


Ping & DNS - my free Android networking tools app
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the difference between DataInputStream and BufferedReader?
 
Similar Threads
send an int value over the network
Input/Output(urgent)
input/output
I / O
input/output