• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

confused with java.io.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got confused while reading java.io.
I has got lot of bytestreams and characterstreams
can some body tell me a simple to remember it
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The io classes that contain the word "Stream" are for bytes. The ones that say "Reader" or "Writer" are for characters.
Basically, you start with an input or an output stream (like System.in for example). Then you can "wrap" other classes around it to add different levels of functionality to your stream.
For example, say you want to read input from the keyboard, one line at a time. How would you do it? System.in is an InputStream and doesn't have methods to read a line of text. You would do something like this:

The trick to this is that there are two classes that form a "bridge" between byte streams and character streams. These classes include the words "Stream" as well as "Reader" or "Writer". They are InputStreamReader and OutputStreamWriter. They take byte streams as arguments and add character stream functionality to them. So if you are starting with a raw byte stream like System.in, you need to use InputStreamReader to move over to character streams. Then you can use whatever character stream class you like to add more methods to your Reader/Writer.
HTH
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic