Managing input and output files in java

Variables and arrays for storage

}     Data is lost either when variable is out of scope or program terminated

}     It is difficult to manage large volume of data

}     To overcome this we uses secondary storage

}     Data stored in secondary is called persistent data

}     file: is the collection of related record

}     Record:composed of several fields

 

Streams in java

}     Input refers to flow of data into a program

}     Output refers to flow of data out of a  program

}     Stream in java is a path along which data flows




}     Streams are classified into two

·         Input stream

Extracts data from the source and sends to the program

·         Output stream

Takes data from the program and sends to the destination


Stream classes           

}     Java.io package contains large number of stream classes for processing all type of data

}     These classes categorized into two groups

·         Byte stream classes

Handle’s i/o operations on bytes

·         Character stream classes

Handle’s i/o operations on characters

}     Both these classes contains special classes to deal with input and output operations independently on various type of devices

Classification of java stream classes














Byte stream classes

}     Designed to provide functional features for creating and manipulating streams and files for reading and writing bytes

}     Java provides two kinds of byte stream classes

·         Input stream classes

·         Output stream classes

 

Input stream classes














}     Used to read 8-bit bytes

}      includes a superclass InputStream

}     a number of subclasses for supporting various input-related functions

}     Performs input functions such

·         Reading bytes

·         Closing stream

·         Marking positions in stream

·         Skipping ahead in a stream

·         Finding the number of bytes


InputStream class methods






Output stream classes















}     Derived from base class OutputStream

}     Several subclasses of the OutputStream can be used for performing the output operations

}     Includes methods to perform

·         Writing bytes

·         Closing streams

·         Flusing streams

 

OutputStream class methods







Character stream classes

}     Were not a part of the language when it was released

}     Used to read and write 16-bit Unicode characters

}     Java provides two kinds of Character stream classes

·         reader stream classes

·         writer stream classes

 

Reader stream classes

}     Designed to read character from the files

}     Reader class is the base class

}     Is functionally very similar to the inputstream classes

}     Reader classes contains methods identical to those available in InputStream class

 

Hierachy of reader stream classes


 









Writer stream classes

}     Designed to perform all ouput operations on files

}     Writer Class is an abstract class which act as a baseclass for all the other writer stream classes

}     All funtions and operations defined here is identical to those in OutputStream class

 

Hierachy of writer stream classes

 













Reading and Writing characters



 

 
































No comments:

Post a Comment