You are on page 1of 1

I/O Streams:

The basic idea about input/output streams is that the program takes input and gives
u output. so when ever you have to do some i/o handling, generally the i/o handling
invols taking some
inputs from external source it can be from a command line, it can be from a file,
it can be from a consumer application, it can be from a hard disk. so the basic
idea is handling this
input output operations we refer as i/o wrt the file sysytem or hard disk. now when
we talk about streams what is an i/o stream so the basic idea is that, you have an
input source, and you
have an output destination now the way the input source send the data to the
destination is via streams. basically that converts the data to 1 and 0 and travels
as a stream. so A program
uses "Input Stream" to to read the data from the source, and a program uses an
"output stream" to write the data to the destination, one at a time.so now that we
build that we build some
understanding on i/o stream. lets have a look at what kind of classes support java
to do this i/o stream kind of operations.
This is the java i/o class hierarchy where we have object super class and
differnt kind of stream classes. here we have input stream output stream, reader
and writer.
here we have inheritance relation ship if we look into this particular section.
java provides to read from a file as fileInputStream and fileOutputStream. there
are more classes under it
but i am showing only a few for not making this session complicative. we also have
a reader class and a writer class which also have an inputStreamReader and
outputStreamWriter. let go into
an example to understand this concept more clearly, for better understanding i have
taking 2 examples Byte stream example, characterstream example. why i have taken 2
different examples is
that when ever you are reading data from a dta source or writing data to a data
source.. so the data either be simple cacter strings like english characters, it
can be tabular for, or
it can be in html file or xml file literally anything it can be mathematical
expressions, or images. thats the reason java created different types of classes.
if you want to work on
particular file you are holding characters then you can use character stream. and
if you dont know what kind of data you are dealing with will contain then you can
use byte stream.
character stream will be internally using the byte stream only but is more simpler
and much more faster faster to use character stream if you just want to read/write
characters. and when
we use character it reads character by character and the byte stream reads byte by
byte at a time. so lets look at the byte stream example at first. i have created a
class Byte stream example
and it has a a main method and them i am using file input stream and file output
stream classes basically what i am trying to do in this example is to read a file
and write to a file.
according to threory when we are using input stream operation we are reading from
file and when i am using output stream operation i am writing to File. i create a
null references then i
enter a try block and inside the try block i basically provide the location from
where the file is to be read.

You might also like