Sunday, 26 January 2014

I/O Basics in java

i/o basics,streams,byte streams:character stream..


I/O Basics

 Java’s support for console I/O is limited and somewhat awkward to use—even in simple example programs. Text-based console I/O is just not very important to Java programming.g, Java does provide strong, flexible support for I/O as it relates to files and networks. Java’s I/O system is cohesive and consistent. In fact, once you understand its fundamentals, the rest of the I/O system is easy to master.


Streams


Java programs perform I/O through streams. Astream is an abstraction that either produces or consumes information. A stream is linked to a physical device by the Java I/O system.All streams behave in the same manner, even if the actual physical devices to which they are linked differ. Thus, the same I/O classes and methods can be applied to any type of device.
This means that an input stream can abstract many different kinds of input: from a disk file,a keyboard, or a network socket. Likewise, an output stream may refer to the console, a disk file, or a network connection.

Byte Streams and Character Streams


Java defines two types of streams: byte and character. Byte streams provide a convenient means for handling input and output of bytes. Byte streams are used, for example, when reading or writing binary data. Character streams provide a convenient means for handling input and output of characters. They use Unicode and, therefore, can be internationalized.

The Byte Stream Classes:


Byte streams are defined by using two class hierarchies. At the top are two abstract classes:InputStreamand OutputStream. The abstract classes InputStream and OutputStream define several key methods that the other stream classes implement. Two of the most important are read( ) and write( ),which, respectively, read and write bytes of data. Both methods are declared as abstract inside InputStream and OutputStream. They are overridden by derived stream classes.


The Byte Stream Classes:

BufferedInputStream:
Buffered input stream.

BufferedOutputStream:
Buffered output stream.

ByteArrayInputStream :
Input stream that reads from a byte array.

ByteArrayOutputStream :
Output stream that writes to a byte array.

DataInputStream:
An input stream that contains methods for reading the Java standard data types.

DataOutputStream:
An output stream that contains methods for writing the Java standard data types.

FileInputStream :
Input stream that reads from a file.

FileOutputStream :
Output stream that writes to a file.

FilterInputStream :
Implements InputStream.

FilterOutputStream :
Implements OutputStream.

InputStream:
Abstract class that describes stream input.

ObjectInputStream :
Input stream for objects.

ObjectOutputStream :
Output stream for objects.

OutputStream :
Abstract class that describes stream output.

PipedInputStream:
Input pipe.

PipedOutputStream:
Output pipe.

PrintStream:
Output stream that contains print( ) and println( ).

PushbackInputStream :
Input stream that supports one-byte “unget,” which returns a byte to the input stream.

RandomAccessFile :
Supports random access file I/O.

SequenceInputStream :
Input stream that is a combination of two or more input streams that will be read sequentially, one after the other.

The Character Stream Classes

Character streams are defined by using two class hierarchies. At the top are two abstract classes, Reader and Writer.The abstract classes Reader and Writer define several key methods that the other stream classes implement. Two of the most important methods are read( ) and write( ), which read and write characters of data, respectively .

The Character Stream I/O Classes:

BufferedReader:
Buffered input character stream.

BufferedWriter :
Buffered output character stream.

CharArrayReader :
Input stream that reads from a character array.

CharArrayWriter:
Output stream that writes to a character array.

FileReader :
Input stream that reads from a file.

FileWriter:
Output stream that writes to a file.

FilterReader:
Filtered reader.
FilterWriter :
Filtered writer.

InputStreamReader:
Input stream that translates bytes to characters.

LineNumberReader:
Input stream that counts lines.

OutputStreamWriter:
Output stream that translates characters to bytes.

PipedReader:
Input pipe.

PipedWriter:
Output pipe.

PrintWriter :
Output stream that contains print( ) and println( ).

PushbackReader:
Input stream that allows characters to be returned to the input stream.

Reader:
Abstract class that describes character stream input.

StringReader:
Input stream that reads from a string.

StringWriter:
Output stream that writes to a string.

Writer :
Abstract class that describes character stream output.



































































































































































No comments :

Post a Comment