At the time of preparing this manuscript, Sun Micro conveyed the
following items to deal with input-output of texts or objects.
- I/O Streams
- Byte Streams: carries integer values of the data added as an
input. (1),
ranging a value 0-255 and 32 being a blank or space between two data
during serialization.
All byte stream classes are the descendents of
InputStream
and
OutputStream
(Read More).
Java uses byte streams to perform input and output of 8-bit
bytes. These classes are abstract classes, therefore can't be stream
directly.
-
FileInputStream in = null;
-
FileOutputStream out = null;
-
I/O
byte streams,
FileInputStream and FileOutputStream .
- Character Streams: Any kind of text data handled by this
stream.
All character stream classes are descended from
Reader and
Writer .(Read
More)
-
FileReader inputStream = null;
-
FileWriter outputStream = null;
- Buffered Streams: the efficiency of the streams mentioned above,
further enhanced with Buffered stream.
-
There are four buffered stream classes used to wrap FileReader or Writer
streams:
-
Create
buffered byte streams:
-
BufferedInputStream and BufferedOutputStream
-
Create
buffered character streams
-
BufferedReader
and BufferedWriter .
- Scanning and Formatting
- Scanning:
-
Scanner
-
BufferedReader(new FileReader("xanadu.txt")));
- Formatting
- I/O from the Command Line
- Data Streams: support binary I/O of primitive data type values like
boolean , char , byte , short ,
int , long , float , double
and Strings. All data streams implement either the two interfaces
namely
DataInput or the
DataOutput interface. This section focuses on the most
widely-used implementations of these interfaces,
DataInputStream and
DataOutputStream .
- Object Stream
- ObjectOutputStream(OOPS)
Link
- File I/Omakes
it easier to write platform-independent code that examines and
manipulates files. The name of this class is misleading:
File
instances represent file names, not files. The file corresponding to the
file name might not even exist.
File Objects
Random Access Files
The New I/O Packages
|
An InputStreamReader is a bridge from byte streams to character streams:
It reads bytes and translates them into characters according to a specified
character encoding. The encoding that it uses may be specified by name,
or the platform's default encoding may be accepted.
Each invocation of one of an InputStreamReader's read() methods may cause
one or more bytes to be read from the underlying byte-input stream. To
enable the efficient conversion of bytes to characters, more bytes may be
read ahead from the underlying stream than are necessary to satisfy the
current read operation.
For top efficiency, consider wrapping an InputStreamReader within a
BufferedReader. For example:
BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
|