设为首页 加入收藏

TOP

Java IO 文件拷贝功能的实现(四)
2018-03-28 09:05:59 】 浏览:831
Tags:Java 文件 拷贝 功能 实现
p; /**
    * Reads some number of bytes from the input stream and stores them into
    * the buffer array <code>b</code>. 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.
    *
    * <p> If the length of <code>b</code> is zero, then no bytes are read and
    * <code>0</code> is returned; otherwise, there is an attempt to read at
    * least one byte. If no byte is available because the stream is at the
    * end of the file, the value <code>-1</code> is returned; otherwise, at
    * least one byte is read and stored into <code>b</code>.
    *
    * <p> The first byte read is stored into element <code>b[0]</code>, the
    * next one into <code>b[1]</code>, and so on. The number of bytes read is,
    * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
    * number of bytes actually read; these bytes will be stored in elements
    * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
    * leaving elements <code>b[</code><i>k</i><code>]</code> through
    * <code>b[b.length-1]</code> unaffected.
    *
    * <p> The <code>read(b)</code> method for class <code>InputStream</code>
    * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
    *
    * @param      b  the buffer into which the data is read.
    * @return    the total number of bytes read into the buffer, or
    *            <code>-1</code> if there is no more data because the end of
    *            the stream has been reached.
    * @exception  IOException  If the first byte cannot be read for any reason
    * other than the end of the file, if the input stream has been closed, or
    * if some other I/O error occurs.
    * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
    * @see        java.io.InputStream#read(byte[], int, int)
    */
    public int read(byte b[]) throws IOException {
        return read(b, 0, b.length);
    }


源码已经很清楚的写出来了,”@param b the buffer into which the data is read.”,参数是要读取到内存中的字节数组,如果再跟下去,我们发现,其实这个方法是调用了 read( byte b[] , int off , int len )
这里写图片描述
其实最后,还是使用的 read() 方法,我们只不过是调用了已经封装好的一些方法。


对于 write( byte b[], int off, int len )方法,源码如下:


    /**
    * Writes <code>len</code> bytes from the specified byte array
    * starting at offset <code>off</code> to this output stream.
    * The general contract for <code>write(b, off, len)</code> is that
    * some of the bytes in the array <code>b</code> are written to the
    * output stream in order; element <c

首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android 自定义ToolBar详细使用 下一篇Java中的Number和Math类简单介绍

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目