img
Method
Description
int available( )
Returns the number of bytes that are now available in the
input buf fer.
void close( )
Closes the invoking stream. Fur ther read attempts will
generate an IOException.
int read( )
Returns an integer representation of the next available byte
of input. ­1 is returned when the end of the file is
encountered.
int read(byte buf fer[ ], int of fset,
Attempts to read up to numBytes bytes into buf fer star ting at
int numBytes)
buf fer[of fset], returning the number of bytes successfully
read. ­1 is returned when the end of the file is encountered.
boolean readBoolean( )
Reads and returns a boolean from the invoking stream.
byte readByte( )
Reads and returns a byte from the invoking stream.
char readChar( )
Reads and returns a char from the invoking stream.
double readDouble( )
Reads and returns a double from the invoking stream.
float readFloat( )
Reads and returns a float from the invoking stream.
void readFully(byte buf fer[ ])
Reads buf fer.length bytes into buf fer. Returns only when all
bytes have been read.
void readFully(byte buf fer[ ],
Reads numBytes bytes into buf fer star ting at buf fer[of fset].
int of fset,
Returns only when numBytes have been read.
int numBytes)
int readInt( )
Reads and returns an int from the invoking stream.
long readLong( )
Reads and returns a long from the invoking stream.
final Object readObject( )
Reads and returns an object from the invoking stream.
shor t readShor t( )
Reads and returns a shor t from the invoking stream.
int readUnsignedByte( )
Reads and returns an unsigned byte from the invoking
stream.
int readUnsignedShor t( )
Reads and returns an unsigned shor t from the invoking
stream.
TABLE 19-9
Commonly Used Methods Defined by ObjectInputStream
A FileOutputStream is created that refers to a file named "serial," and an
ObjectOutputStream is created for that file stream. The writeObject( ) method
of ObjectOutputStream is then used to serialize our object. The object output
stream is flushed and closed.
A FileInputStream is then created that refers to the file named "serial," and
an ObjectInputStream is created for that file stream. The readObject( ) method of
ObjectInputStream is then used to deserialize our object. The object input stream
is then closed.
Note that MyClass is defined to implement the Serializable interface. If this is not
done, a NotSerializableException is thrown. Try experimenting with this program by
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home