public class DataInputStream extends FilterInputStream implements DataInput
输入流是不一定安全的多线程访问。线程安全是可选的,是在这个类中的方法的用户的责任。
DataOutputStream
in| Constructor and Description |
|---|
DataInputStream(InputStream in)
创建一个输入流InputStream使用指定的标。
|
| Modifier and Type | Method and Description |
|---|---|
int |
read(byte[] b)
读取一定数量的字节从包含输入流并存入缓冲区阵列
b。
|
int |
read(byte[] b, int off, int len)
读到
len从包含输入流读入字节数组数据字节。
|
boolean |
readBoolean()
看到的
DataInput的
readBoolean方法一般合同。
|
byte |
readByte()
看到的
DataInput的
readByte方法一般合同。
|
char |
readChar()
看到的
DataInput的
readChar方法一般合同。
|
double |
readDouble()
看到的
DataInput的
readDouble方法一般合同。
|
float |
readFloat()
看到的
DataInput的
readFloat方法一般合同。
|
void |
readFully(byte[] b)
看到的
DataInput的
readFully方法一般合同。
|
void |
readFully(byte[] b, int off, int len)
看到的
DataInput的
readFully方法一般合同。
|
int |
readInt()
看到的
DataInput的
readInt方法一般合同。
|
String |
readLine()
过时的。
此方法没有正确地将字节转换为字符。作为 JDK 1.1,阅读文本行的首选方式是通过
BufferedReader.readLine()方法。程序使用的DataInputStream类的台词可以转换的形式替换代码中使用BufferedReader类:
:
|
long |
readLong()
看到的
DataInput的
readLong方法一般合同。
|
short |
readShort()
看到的
DataInput的
readShort方法一般合同。
|
int |
readUnsignedByte()
看到的
DataInput的
readUnsignedByte方法一般合同。
|
int |
readUnsignedShort()
看到的
DataInput的
readUnsignedShort方法一般合同。
|
String |
readUTF()
看到的
DataInput的
readUTF方法一般合同。
|
static String |
readUTF(DataInput in)
|
int |
skipBytes(int n)
看到的
DataInput的
skipBytes方法一般合同。
|
available, close, mark, markSupported, read, reset, skippublic DataInputStream(InputStream in)
in -指定输入流
public final int read(byte[] b)
throws IOException
b。实际读取的字节数作为一个整数返回。此方法块,直到输入数据可用,检测到文件结束,或抛出异常。
如果b是空的,一个NullPointerException抛出。如果b长度为零,那么没有字节读0返回;否则,在试图读至少一个字节。如果没有可用的字节,因为流到达文件尾,价值-1返回;否则,至少有一个字节读入b。
第一个字节存储在单元b[0],未来一到b[1],等等。读取的字节数,最多等于b长度。让k是实际读取的字节数目;这些字节将通过b[k-1]存储在元素b[0],离开b[k] b[b.length-1]元素通过影响。
的read(b)方法具有相同的效果:
read(b, 0, b.length)
read 方法重写,继承类
FilterInputStream
b -缓冲区中读取数据。
-1如果没有更多的数据,因为已到达流的末尾。
IOException -如果第一个字节不能读比其他文件的任何理由,流已经关闭,数据输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in,
InputStream.read(byte[], int, int)
public final int read(byte[] b,
int off,
int len)
throws IOException
len字节从包含输入流到字节数组数据。尝试读
len字节为多,但数量较少,可以读,可能为零。实际读取的字节数作为一个整数返回。
此方法块,直到输入数据可用,检测到文件结束,或抛出异常。
如果len是零,那么没有字节读0返回;否则,在试图读至少一个字节。如果没有可用的字节,因为流到达文件尾,价值-1返回;否则,至少有一个字节读入b。
第一个字节存储在单元b[off],未来一到b[off+1],等等。读取的字节数,最多等于len。设K是实际读取的字节数目;这些字节将通过b[off+k-1]存储在元素b[off],离开b[off+k] b[off+len-1]元素通过影响。
在任何情况下,元件b[0]通过b[off]和元素b[off+len]通过b[b.length-1]不受影响。
read 方法重写,继承类
FilterInputStream
b -缓冲区中读取数据。
off -开始抵消目标数组
b
len -的最大字节数读。
-1如果没有更多的数据,因为已到达流的末尾。
null
b
NullPointerException。
IndexOutOfBoundsException -如果
off是负的,
len是负的,或
len大于
b.length - off
IOException -如果第一个字节不能读比其他文件的任何理由,流已经关闭,数据输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in,
InputStream.read(byte[], int, int)
public final void readFully(byte[] b)
throws IOException
DataInput的
readFully方法一般合同。
此操作的字节从包含的输入流中读取。
readFully 接口
DataInput
b -缓冲区中读取数据。
EOFException如果输入流到达终点之前阅读所有字节。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final void readFully(byte[] b,
int off,
int len)
throws IOException
DataInput的
readFully方法一般合同。
此操作的字节从包含的输入流中读取。
readFully 接口
DataInput
b -缓冲区中读取数据。
off的起始偏移量的数据。
len -字节数读。
EOFException如果输入流到达终点之前阅读所有字节。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final int skipBytes(int n)
throws IOException
DataInput的
skipBytes方法一般合同。
此操作的字节从包含的输入流中读取。
skipBytes 接口
DataInput
n -字节数被跳过。
IOException如果包含输入流不支持查找,或流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
public final boolean readBoolean()
throws IOException
DataInput的
readBoolean方法一般合同。
此操作的字节从包含的输入流中读取。
readBoolean 接口
DataInput
boolean阅读的价值。
EOFException如果输入流已结束。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final byte readByte()
throws IOException
DataInput的
readByte方法一般合同。
此操作的字节从包含的输入流中读取。
readByte 接口
DataInput
byte签署。
EOFException如果输入流已结束。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final int readUnsignedByte()
throws IOException
DataInput的
readUnsignedByte方法一般合同。
此操作的字节从包含的输入流中读取。
readUnsignedByte 接口
DataInput
EOFException如果输入流已结束。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final short readShort()
throws IOException
DataInput的
readShort方法一般合同。
此操作的字节从包含的输入流中读取。
readShort 接口
DataInput
EOFException -如果这个输入流读两字节之前到达终点。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final int readUnsignedShort()
throws IOException
DataInput的
readUnsignedShort方法一般合同。
此操作的字节从包含的输入流中读取。
readUnsignedShort 接口
DataInput
EOFException -如果这个输入流读两字节之前到达终点。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final char readChar()
throws IOException
DataInput的
readChar方法一般合同。
此操作的字节从包含的输入流中读取。
readChar 接口
DataInput
char。
EOFException -如果这个输入流读两字节之前到达终点。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final int readInt()
throws IOException
DataInput的
readInt方法的一般合同。
此操作的字节从包含的输入流中读取。
readInt 接口
DataInput
int。
EOFException -如果这个输入流读四个字节之前到达终点。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final long readLong()
throws IOException
DataInput的
readLong方法一般合同。
此操作的字节从包含的输入流中读取。
readLong 接口
DataInput
long。
EOFException -如果这个输入流读八个字节之前到达终点。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
FilterInputStream.in
public final float readFloat()
throws IOException
DataInput的
readFloat方法一般合同。
此操作的字节从包含的输入流中读取。
readFloat 接口
DataInput
float。
EOFException -如果这个输入流读四个字节之前到达终点。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
readInt(),
Float.intBitsToFloat(int)
public final double readDouble()
throws IOException
DataInput的
readDouble方法一般合同。
此操作的字节从包含的输入流中读取。
readDouble 接口
DataInput
double。
EOFException -如果这个输入流读八个字节之前到达终点。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
readLong(),
Double.longBitsToDouble(long)
@Deprecated public final String readLine() throws IOException
BufferedReader.readLine()方法。程序使用的DataInputStream类的台词可以转换的形式替换代码中使用BufferedReader类:
DataInputStream d = new DataInputStream(in);
:
BufferedReader d
= new BufferedReader(new InputStreamReader(in));
DataInput的
readLine方法一般合同。
此操作的字节从包含的输入流中读取。
readLine 接口
DataInput
IOException如果I/O错误发生。
BufferedReader.readLine(),
FilterInputStream.in
public final String readUTF() throws IOException
DataInput的
readUTF方法一般合同。
此操作的字节从包含的输入流中读取。
readUTF 接口
DataInput
EOFException如果输入流到达终点之前阅读所有字节。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
UTFDataFormatException如果字节没有表示一个有效的修改一个字符串编码UTF-8。
readUTF(java.io.DataInput)
public static final String readUTF(DataInput in) throws IOException
in -数据输入流。
EOFException如果输入流到达终点之前的所有字节。
IOException -流已经关闭,包含输入流不支持读取完毕后,或发生I/O错误。
UTFDataFormatException如果字节没有表示一个有效的修改UTF-8 Unicode字符串编码。
readUnsignedShort()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.