• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the difference between DataInputStream and BufferedReader?

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its implied that the BufferdReader provides buffering capabilities .
Look the specifications for more information.


Hope this helps
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic