Managing Input
Managing Input
FILES IN JAVA
FILE HANDLING
CONCEPT OF STREAMS:
In file processing , input refers to flow of data into a program and
output means the flow of data out of a program
input to a program may come from the keyboard ,the mouse, the memory, the
disk, a network, another program.
similarly, output from a program may go to the screen, the printer, the
memory, the disk, a network, or another
program.
STREAM CLASS:
A stream in java in path along which data flows(LIKE A RIVER OR A PIPE
ALONG WHICH WATER FLOWS). It has a
source (OF DATA) and a destination.
The concept of sending data from one stream to another(LIKE ONE PIPE
FEEDING INTO ANOTHER PIPE) has made
streams in java a powerful tool for file processing.
Input
SOURCE
PROGRAM
(a) Reading data into a program
PROGRAM
DESTINATION
(b) Writing data into a
destination
STREAM CLASSES:
The java.io package contains a large number of stream classes that
provide capabilities for
processing all types of data. These classes may be categorized into two
groups based on the
data type on which they operate:
1. Byte stream classes that provide support for handling I/O operations
on bytes.
2. Character stream classes that provide support for managing I/O
operations on characters.
Character
Byte Stream
Stream
Classes
Classes
Memory
Memory File Pipe
File Pipe
The InputStream class defines methods for performing input functions such
as
• Reading bytes
• Closing streams
• Marking positions in streams
• Skipping ahead in a stream
• Finding the number of bytes in stream
Summary of InputStream methods:
Method Description
ὸ Output stream classes are derived from the base class OutputStream.
ὸ Like InputStream the OutputStream is an abstract class and therefore
we cannot instantiate
it.
ὸ The several subclasses of the OutputStream can be used for performing
the output
operations.
ὸ The OutputStream includes methods that are designed to perform the
following tasks
Summary of OutputStream methods:
Method Description
operations o files
Writer stream classes are designed tot write characters.
Hierarchy of reader stream classes:
Object
Reader
BufferedReader
StringReader
CharArrayReader PipeReader
InputStreamReader FilterReader
FileReader PushbackReader