java.io
Class InputStream(捡着翻译,有些觉得没必要)
java.lang.Object java.io.InputStream
-
All Implemented Interfaces:
- Closeable
-
Direct Known Subclasses:
- AudioInputStream, ByteArrayInputStream, FileInputStream, FilterInputStream, InputStream, ObjectInputStream, PipedInputStream, SequenceInputStream, StringBufferInputStream
This abstract class is the superclass of all classes representing an input stream of bytes.
Applications that need to define a subclass of InputStream
must always provide a method that returns the next byte of input.
-
Since:
- JDK1.0 See Also:
-
BufferedInputStream
,ByteArrayInputStream
,DataInputStream
,FilterInputStream
,read()
,OutputStream
,PushbackInputStream
这个抽象类是所有字节输入流的父类。所有实现InputStream的子类必须提供一个方法来返回对输入字节的读取。
read
public int read(byte[] b, int off, int len) throws IOException
-
Reads up to
len
bytes of data from the input stream into an array of bytes. An attempt is made to read as many aslen
bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.This method blocks until input data is available, end of file is detected, or an exception is thrown.
If
len
is zero, then no bytes are read and0
is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value-1
is returned; otherwise, at least one byte is read and stored intob
.The first byte read is stored into element
b[off]
, the next one intob[off+1]
, and so on. The number of bytes read is, at most, equal tolen
. Let k be the number of bytes actually read; these bytes will be stored in elementsb[off]
throughb[off+
k-1]
, leaving elementsb[off+
k]
throughb[off+len-1]
unaffected.In every case, elements
b[0]
throughb[off]
and elementsb[off+len]
throughb[b.length-1]
are unaffected.The
read(b,
off,
len)
method for classInputStream
simply calls the methodread()
repeatedly. If the first such call results in anIOException
, that exception is returned from the call to theread(b,
off,
len)
method. If any subsequent call toread()
results in aIOException
, the exception is caught and treated as if it were end of file; the bytes read up to that point are stored intob
and the number of bytes read before the exception occurred is returned. The default implementation of this method blocks until the requested amount of input datalen
has been read, end of file is detected, or an exception is thrown. Subclasses are encouraged to provide a more efficient implementation of this method. -
从输入流中读取len的长度到字节数组b中。这个方法尝试去读len的长度,但可能会读到比这个长度短的字节数。
读到的字节数将作为read的返回值返回,读不到将返回-1。
如果len为0,则读不到任何bytes,返回值为0;否则,read试图去读至少一个字节。
public long skip(long n) throws IOException跳过n个字节后读取,返回值为实际跳过的字节数