|
Chapter 11 The java.io Package |
|
DataInput
Name
DataInput
- Interface Name:
-
java.io.DataInput
- Super-interface:
-
None
- Immediate Sub-interfaces:
-
java.io.ObjectInput
- Implemented By:
-
java.io.DataInputStream,
java.io.RandomAccessFile
- Availability:
-
JDK 1.0 or later
The DataInput interface defines
methods for reading primitive data types and lines of text from an input
stream in a machine-independent manner. All multibyte quantities are assumed
to be in a format that stores the most significant byte as the first byte
and the least significant byte as the last byte.
public abstract interface java.io.DataInput {
// Methods
public abstract boolean readBoolean();
public abstract byte readByte();
public abstract char readChar();
public abstract double readDouble();
public abstract float readFloat();
public abstract void readFully(byte[] b);
public abstract void readFully(byte[] b, int off, int len);
public abstract int readInt();
public abstract String readLine();
public abstract long readLong();
public abstract short readShort();
public abstract int readUnsignedByte();
public abstract int readUnsignedShort();
public abstract String readUTF();
public abstract int skipBytes(int n);
}
- Returns
-
The boolean value read from
the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a byte as a
boolean value. A byte that contains a zero is read
as false; that which contains a nonzero is read as
true.
- Returns
-
The byte value read from the
stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a signed 8-bit byte.
- Returns
-
The char value read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a 16-bit char.
- Returns
-
The double value read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a 64-bit double
quantity.
- Returns
-
The float value read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a 32-bit float
quantity.
- Parameters
-
- b
-
The array to fill.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads bytes into the given array b
until the array is full.
- Parameters
-
- b
-
The array to fill.
- off
-
An offset into the array.
- len
-
The number of bytes to read.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads len bytes into the given array, starting
at offset off.
- Returns
-
The int value read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a 32-bit int
quantity.
- Returns
-
A String that contains the
line read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a String from the current
position through the next line terminator. Implementations of this
method should take care to look for any line terminator:
"\n", "\r", or
"\r\n".
- Returns
-
The long value read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a 64-bit long quantity.
- Returns
-
The short value read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a 16-bit short quantity.
- Returns
-
The unsigned byte value read
from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads an 8-bit byte
as an unsigned quantity.
- Returns
-
The unsigned short value read
from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method reads a 16-bit short
as an unsigned quantity.
- Returns
-
The String read from the stream.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- UTFDataFormatException
-
If the bytes do not represent a valid UTF-8 encoding.
- Description
-
This method reads a UTF-8 format String.
See Appendix B, The UTF-8 Encoding, for information on the UTF-8 encoding.
- Parameters
-
- n
-
The number of bytes to
skip.
- Returns
-
The actual number of skipped bytes.
- Throws
-
- EOFException
-
If the end of the file is encountered.
- IOException
-
If any other kind of I/O error occurs.
- Description
-
This method skips over n bytes.
DataInputStream,
EOFException,
IOException,
ObjectInput,
RandomAccessFile,
UTFDataFormatException
|
|