InputStream

java.io
Class InputStream(捡着翻译,有些觉得没必要)

java.lang.Object
  extended by java.io.InputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
AudioInputStream, ByteArrayInputStream, FileInputStream, FilterInputStream, InputStream, ObjectInputStream, PipedInputStream, SequenceInputStream, StringBufferInputStream
public abstract class InputStream
   
   
    
    extends 
    
    Object
   
   
   
   
    
    implements 
    
    Closeable
   
   

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 as len 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 and 0 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 to len. Let k be the number of bytes actually read; these bytes will be stored in elementsb[off] through b[off+k-1], leaving elementsb[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off] and elementsb[off+len] through b[b.length-1] are unaffected.

The read(b, off, len) method for class InputStream simply calls the method read() repeatedly. If the first such call results in anIOException, that exception is returned from the call to the read(b,off, len) method. If any subsequent call to read() 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个字节后读取,返回值为实际跳过的字节数


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值