File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the difference between DataInputStream and BufferedReader?

 
Shaik Muhammad
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its implied that the BufferdReader provides buffering capabilities .
Look the specifications for more information.


Hope this helps
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 565
Android Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic