Name
DataInputStream
Synopsis
This
class is a type of FilterInputStream
that allows
you to read
binary
representations of Java primitive data types in a portable way.
Create a DataInputStream
by specifying the
InputStream
that is to be filtered in the call to
the constructor. DataInputStream
reads only
primitive Java types; use ObjectInputStream
to
read object values.
Many of the methods read and return a single Java primitive type, in
binary format, from the stream.
readUnsignedByte( )
and
readUnsignedShort( )
read
unsigned values and
return them as int
values, since unsigned
byte
and short
types are
not supported in Java. read(
)
reads data into an array of bytes, blocking until at least some data
is available. By contrast, readFully(
)
reads data into an array of
bytes, but blocks until all requested data becomes available.
skipBytes( )
blocks until the specified
number of bytes have been read and discarded. readLine(
)
reads characters from the stream
until it encounters a newline, a carriage return, or a
newline/carriage return pair. The returned string is not terminated
with a newline or carriage return. This method is deprecated as of
Java 1.1; see BufferedReader
for an alternative.
readUTF( )
reads a string of Unicode text encoded
in a slightly modified version of the UTF-8 transformation format.
UTF-8 is an ASCII-compatible encoding of Unicode characters that is often used for the transmission and storage of Unicode text. This class uses a modified UTF-8 encoding ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.